Last active
January 12, 2020 16:12
-
-
Save endeepak/bdae1c52603b7dd402c4aef68f95cd4b to your computer and use it in GitHub Desktop.
NodeJS Request Log Tracing : Logger
This file contains 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
const { createLogger, transports, format } = require('winston'); | |
const {combine, printf} = format; | |
const requestTracing = require('request-tracing'); // Wrapper library to read the tracing information from CLS context | |
const loggerFormat = printf((info) => { | |
const tracingId = requestTracing.getTracingId(); // Same as requestTracingNamespace.get(tracingIdContextKeyName); | |
let formatObject = `${info.level || '-'} ${info.timestamp || '-'} ${tracingId || '-'} ${info.message}`; | |
// ... | |
return formatObject; | |
}); | |
const logger = createLogger({ | |
transports: [ | |
new transports.Console({ | |
level: process.env.LOG_LEVEL, | |
format: combine( | |
// ... | |
loggerFormat | |
) | |
}) | |
] | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment