Skip to content

Instantly share code, notes, and snippets.

Created June 11, 2020 05:27
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save anandsunderraman/1bd47e0ce51951166d36ec69cac4d8c9 to your computer and use it in GitHub Desktop.
node structured logging configuration
'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