0.2.9 • Published 2 years ago

@lindorm-io/core-logger v0.2.9

Weekly downloads
-
License
AGPL-3.0-or-later
Repository
-
Last release
2 years 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

2 years ago

0.2.7

2 years ago

0.2.6

2 years ago

0.2.8

2 years ago

0.2.3

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.1

2 years ago

0.2.2

2 years ago

0.2.0

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago