Skip to content

Instantly share code, notes, and snippets.

@endeepak
Last active January 12, 2020 16:12
Show Gist options
  • Save endeepak/bdae1c52603b7dd402c4aef68f95cd4b to your computer and use it in GitHub Desktop.
Save endeepak/bdae1c52603b7dd402c4aef68f95cd4b to your computer and use it in GitHub Desktop.
NodeJS Request Log Tracing : Logger
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