@via-apertus/winston
v0.1.14
Published
Winston logger for @via-apertus
Readme
@via-apertus/winston
Installation
npm install @via-apertus/winstonSetup
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.
