Skip to content

Instantly share code, notes, and snippets.

@kamikat
Created May 23, 2018 04:37
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 kamikat/a815f2e025d4a5576f7de31ec19c47f3 to your computer and use it in GitHub Desktop.
Save kamikat/a815f2e025d4a5576f7de31ec19c47f3 to your computer and use it in GitHub Desktop.
256color compatible logger configuration for winston.
var clc = require('cli-color');
var { Logger, transports } = require('winston');
var { formatter, timestamp } = require('winston-console-formatter')({
colors: ((term) => (~term.indexOf('256')) ? {
silly: clc.xterm(33),
debug: clc.xterm(207),
info: clc.xterm(48),
warn: clc.xterm(226),
error: clc.xterm(196),
verbose: clc.xterm(8),
} : {
silly: clc.blue,
debug: clc.cyan,
info: clc.green,
warn: clc.yellow,
error: clc.red,
verbose: clc.white,
})(process.env.TERM || '')
});
var logger = new Logger({
level: process.env.LOG_LEVEL || 'info',
transports: [
new transports.Console({
formatter,
timestamp
})
]
});
module.exports = { logger };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment