Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rahulballal/ca903a59fa2c6d39810e4a75a5a65a2c to your computer and use it in GitHub Desktop.
Save rahulballal/ca903a59fa2c6d39810e4a75a5a65a2c to your computer and use it in GitHub Desktop.
Winston / Stackdriver severity level
const winston = require('winston');
const { LEVEL } = require('triple-beam');
const SeverityLookup = {
'default': 'DEFAULT',
'silly': 'DEFAULT',
'verbose': 'DEBUG',
'debug': 'DEBUG',
'http': 'notice',
'info': 'info',
'warn': 'WARNING',
'error': 'ERROR',
}
const stackdriverSeverityFormat = winston.format((info) => ({
...info,
// Add severity to your log
severity: SeverityLookup[info[LEVEL]] || SeverityLookup['default'],
}));
const formatters = [
winston.format.timestamp(),
// Add the format that supplements the JSON with severity
stackdriverSeverityFormat(),
winston.format.json(),
];
const logger = winston.createLogger({
level: 'silly',
format: winston.format.combine(...formatters),
stderrLevels: ['error'],
transports: [
new winston.transports.Console(),
],
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment