0.1.14 • Published 4 years ago

@via-apertus/winston v0.1.14

Weekly downloads
-
License
ISC
Repository
github
Last release
4 years ago

@via-apertus/winston

Installation

npm install @via-apertus/winston

Setup

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

const winston = new Logger({
  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;

Use the logger

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

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

Add a session logger

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

Add a filter

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

Why?

Winston is great, however I find myself making the same setup in every project I make. I wanted to create something simple and heavily opinionated so that setting it up is easy.

0.1.14

4 years ago

0.1.13

4 years ago

0.1.11

4 years ago

0.1.12

4 years ago

0.1.10

4 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.4

4 years ago

0.1.3

4 years ago

0.1.5

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago