@lindorm-io/core-logger
TypeScript icon, indicating that this package has built-in type declarations

0.2.9 • Public • Published

@lindorm-io/core-logger

Simple core logger for lindorm.io packages.

Installation

npm install --save @lindorm-io/core-logger

Setup

import { ConsoleLogger, LogLevel } from "@lindorm-io/core-logger";

const logger = new ConsoleLogger();

logger.addConsole(LogLevel.INFO, { readable: true, colours: true, timestamp: true });

Usage

Logging

The logger accepts a message as first argument, and an object or an error as second (optional) argument.

logger.info("this is the logger message", {
  this_is: "the logger details object"
});

logger.error("this is the message", new Error("with an error and error stack"));

Add a child logger

You can create child logger with further context data to easily separate where the message was sent.

export const childLogger = logger.createChildLogger([
  "context1",
  "context2",
  "context3",
]);

Add a session logger

You can create a child logger with specific session data to easily separate log rows for different sessions.

export const sessionLogger = logger.createSessionLogger({
  session: "object",
  request_id: "id",
});

Add a filter

You can hide sensitive data from logs by adding a filter with object path.

logger.addFilter([
  "req.body.sensitive",
]);

logger.info("MESSAGE", req);
// MESSAGE { req: { body: { sensitive: "[Filtered]", } } }

Readme

Keywords

none

Package Sidebar

Install

npm i @lindorm-io/core-logger

Weekly Downloads

1

Version

0.2.9

License

AGPL-3.0-or-later

Unpacked Size

38.4 kB

Total Files

52

Last publish

Collaborators

  • princejonn