Skip to content

Instantly share code, notes, and snippets.

@amirelemam
Last active April 19, 2021 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amirelemam/5865647f1ea26f181d3e19f448f0f7ae to your computer and use it in GitHub Desktop.
Save amirelemam/5865647f1ea26f181d3e19f448f0f7ae to your computer and use it in GitHub Desktop.
Logging with winston
const winston = require('winston');
const customLevels = {
levels: {
error: 0,
warn: 1,
info: 2,
http: 3,
verbose: 4,
debug: 5,
silly: 6,
},
colors: {
error: 'red',
warn: 'yellow',
info: 'green',
http: 'blue',
verbose: 'white',
debug: 'white',
silly: 'white',
},
};
winston.addColors(customLevels.colors);
const logger = winston.createLogger({
transports: [
new winston.transports.Console({
format: winston.format.combine(
winston.format.colorize(),
winston.format.timestamp({
format: 'YYYY-MM-DDHH:mm:ss',
}),
winston.format.printf(
(info) => `${info.timestamp} ${info.level}: ${info.message}`
)
),
level: process.env.LOGGING_LEVEL || 'info',
}),
],
});
module.exports = logger;
module.exports.stream = {
write: function (message, encoding) {
logger.http(message);
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment