Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
/ lu-logger Public archive

⛔️ DEPRECATED - Logging package for the lu-greenfield project

License

Notifications You must be signed in to change notification settings

BonnierNews/lu-logger

Repository files navigation

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

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/<environment>.json.

Example

{
  "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 <app root>/logs/<NODE_ENV>.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.

{
  "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, by using an 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

const express = require("express");

const { debugMeta } = require("lu-logger");

const app = express();

app.use(debugMeta.initMiddleware((req) => req.debugMeta));

About

⛔️ DEPRECATED - Logging package for the lu-greenfield project

Resources

License

Stars

Watchers

Forks

Packages

No packages published