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

0.5.13 • Public • Published

@lindorm-io/winston

Simple winston logger for lindorm.io packages.

Installation

npm install --save @lindorm-io/winston

Setup

import { WinstonLogger, LogLevel } from "@lindorm-io/winston";

const pkg = fs.readFileSync(path.join(__dirname, "..", "package.json"), { encoding: "utf8" });
const { name, version } = JSON.parse(pkg);

const winston = new WinstonLogger({
  context: "logger-context",
  packageName: name,
  packageVersion: version,
});

winston.addConsole(LogLevel.INFO);
winston.addTail(LogLevel.DEBUG);
winston.addFileTransport(LogLevel.ERROR);
winston.addFileTransport(LogLevel.SILLY);

export default winston;

Usage

Logging

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

winston.info("this is the logger message", {
  this_is: "the logger details object"
});
winston.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 = winston.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 = winston.createSessionLogger({
  session: "object",
  request_id: "id",
});

Add a filter

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

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

Readme

Keywords

none

Package Sidebar

Install

npm i @lindorm-io/winston

Weekly Downloads

7

Version

0.5.13

License

AGPL-3.0-or-later

Unpacked Size

34.7 kB

Total Files

32

Last publish

Collaborators

  • princejonn