Skip to content

Instantly share code, notes, and snippets.

@sylvaindesve
Last active January 9, 2020 11:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sylvaindesve/bec04cbc5ace03f8fff10f1fca437a5e to your computer and use it in GitHub Desktop.
Save sylvaindesve/bec04cbc5ace03f8fff10f1fca437a5e to your computer and use it in GitHub Desktop.
Winston
import * as winston from "winston";
const { Console, File } = winston.transports;
const { combine, timestamp, logstash, colorize, padLevels, printf, label } = winston.format;
const consoleFormat = combine(
colorize(),
padLevels(),
timestamp(),
printf(info => `${info.timestamp} ${info.level}: ${info.message}`)
);
const logger = winston.createLogger({
level: 'info',
defaultMeta: { application: 'myapp', version: "1.0.19753" },
transports: [
new Console({ format: consoleFormat }),
new File({ filename: 'app.log', format: combine(timestamp(), logstash()) })
]
});
const childLogger = logger.child({ userId: "toto" });
childLogger.info('Hello there', { time: 3 });
childLogger.warn('Beware !', { time: 12 });
childLogger.error('Oups !', { time: 7 });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment