-
-
Save rahulballal/ca903a59fa2c6d39810e4a75a5a65a2c to your computer and use it in GitHub Desktop.
Winston / Stackdriver severity level
This file contains hidden or 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 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