0.2.9 • Published 6 months ago

@lindorm-io/core-logger v0.2.9

Weekly downloads
-
License
AGPL-3.0-or-later
Repository
-
Last release
6 months ago

@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]", } } }
0.2.9

6 months ago

0.2.7

1 year ago

0.2.6

1 year ago

0.2.8

11 months ago

0.2.3

1 year ago

0.2.5

1 year ago

0.2.4

1 year ago

0.2.1

1 year ago

0.2.2

1 year ago

0.2.0

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago