Created
June 11, 2020 05:27
-
-
Save anandsunderraman/1bd47e0ce51951166d36ec69cac4d8c9 to your computer and use it in GitHub Desktop.
node structured logging configuration
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
'use strict'; | |
const winston = require('winston'); | |
const MESSAGE = Symbol.for('message'); | |
const jsonFormatter = (logEntry) => { | |
const base = { timestamp: new Date() }; | |
const json = Object.assign(base, logEntry) | |
logEntry[MESSAGE] = JSON.stringify(json); | |
return logEntry; | |
}; | |
exports.logger = winston.createLogger({ | |
format: winston.format(jsonFormatter)(), | |
transports: new winston.transports.Console(), | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment