Last active
January 9, 2020 11:00
-
-
Save sylvaindesve/bec04cbc5ace03f8fff10f1fca437a5e to your computer and use it in GitHub Desktop.
Winston
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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