Skip to content

Instantly share code, notes, and snippets.

@vanduc1102
Last active May 28, 2021 07:54
Show Gist options
  • Save vanduc1102/187bde18ef0e334404eaf88ed5209ee3 to your computer and use it in GitHub Desktop.
Save vanduc1102/187bde18ef0e334404eaf88ed5209ee3 to your computer and use it in GitHub Desktop.
Here is my logger.js with winston": "^3.1.0
const { createLogger, format, transports } = require('winston');
const { combine, timestamp, printf, colorize, splat } = format;
const myFormat = printf((info) => {
if (info.meta && info.meta instanceof Error) {
return `${info.timestamp} ${info.level} ${info.message} : ${info.meta.stack}`;
}else if(info.stack){
return `${info.timestamp} ${info.level} ${info.message} : ${info.stack}`;
}
return `${info.timestamp} ${info.level}: ${info.message}`;
});
const LOG_LEVEL = process.env.LOG_LEVEL || 'debug';
const logger = createLogger({
transports: [
new (transports.Console)(
{
level: LOG_LEVEL,
format: combine(
colorize(),
timestamp(),
splat(),
myFormat
)
}
)
]
});
module.exports = logger;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment