0.5.13 • Published 2 years ago

@lindorm-io/winston v0.5.13

Weekly downloads
1
License
AGPL-3.0-or-later
Repository
-
Last release
2 years ago

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

2 years ago

0.5.12

2 years ago

0.5.10

2 years ago

0.5.11

2 years ago

0.5.8

2 years ago

0.5.7

2 years ago

0.5.9

2 years ago

0.5.6

2 years ago

0.5.5

2 years ago

0.4.10

2 years ago

0.4.11

2 years ago

0.5.4

2 years ago

0.5.3

2 years ago

0.5.0

2 years ago

0.5.2

2 years ago

0.5.1

2 years ago

0.4.9

3 years ago

0.4.8

3 years ago

0.4.5

3 years ago

0.4.4

3 years ago

0.4.7

3 years ago

0.4.6

3 years ago

0.4.3

3 years ago

0.1.11

3 years ago

0.1.12

3 years ago

0.1.13

3 years ago

0.3.0

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.2.2

3 years ago

0.4.2

3 years ago

0.1.10

3 years ago

0.1.9

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago