Skip to content

Instantly share code, notes, and snippets.

@mdesanti
Created October 28, 2016 12:05
Show Gist options
  • Save mdesanti/542b6aedf5593ce1da53aed96f845839 to your computer and use it in GitHub Desktop.
Save mdesanti/542b6aedf5593ce1da53aed96f845839 to your computer and use it in GitHub Desktop.
const winston = require('winston'),
moment = require('moment'),
config = require('../../config/config').config,
getNamespace = require('cls-hooked').getNamespace;
exports.logger = new winston.Logger({
transports: [
new winston.transports.Console({
formatter: (options) => {
const ns = getNamespace('application');
const requestId = ns ? ns.get('requestId') : '';
const logLevel = options.level.toUpperCase();
const time = moment();
const message = options.message || '';
return JSON.stringify({
timestamp: time.toISOString(),
logLevel,
message,
requestId,
service: 'Microservice B'
});
}
})
]
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment