Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bonniernews/lu-logger
Logging package for the lu-greenfield project
https://github.com/bonniernews/lu-logger
Last synced: about 8 hours ago
JSON representation
Logging package for the lu-greenfield project
- Host: GitHub
- URL: https://github.com/bonniernews/lu-logger
- Owner: BonnierNews
- License: mit
- Created: 2018-02-20T09:53:13.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-04-15T09:43:28.000Z (7 months ago)
- Last Synced: 2024-04-23T03:38:27.455Z (7 months ago)
- Language: JavaScript
- Size: 547 KB
- Stars: 0
- Watchers: 105
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# DEPRECATED
As of September 2024 this package is deprecated and will receive no further updates.
Any internal changes should be made directly in `lu-greenfield`.
# lu-logger
![Node.js CI](https://github.com/BonnierNews/lu-logger/actions/workflows/nodejs.yml/badge.svg)
## Purpose and features
File name and line number of the log caller is also added when logging in debug level.
## Configuration
A configuration object must be present in `config/.json`.
### Example
```json
{
"loging": {
"log": "stdout", // Or file, required
"logLevel": "debug", // Minimum level to log
"logJson": true // Log JSON objects or string messages, defaults to true
}
}
```## Log output mode
When log mode `file` is enabled, the log will be written to a file at `/logs/.log` directory, where `app root` is the folder containing the `package.json` file.
Log mode `stdout` will log to stdout.### Example
### #JSON object in the log
The JSON below is an example of a log entry when `logJson` is set to true (or omitted) and `logLevel` is set to debug.
```json
{
"metaData": {
"correlationId": "some-epic-id"
},
"level": "debug",
"message": "This is the log message",
"timestamp": "2018-02-21T12:22:19.150Z"
}
```## Debug metadata
This library provides a mechanism for automatically logging debug metadata (e.g. correlation IDs).
This is implemented with inspiration from [this article](https://dev.to/elmatella/my-logging-strategy-for-express-1mk8),
by using an [`AsyncLocalStorage`](https://nodejs.org/api/async_context.html#class-asynclocalstorage) variable,
which is local to each `async` context.
It then provides a middleware factory for Express which sets this from the request and then logs it out automatically.
The calling library is free to define how to get the metadata from the request.
As an example```js
const express = require("express");const { debugMeta } = require("lu-logger");
const app = express();
app.use(debugMeta.initMiddleware((req) => req.debugMeta));
```