Created
November 13, 2018 09:02
-
-
Save kamikat/577084d2f63f4d0125f76e59777baa89 to your computer and use it in GitHub Desktop.
Colorized logger of [email protected] (boilerplate)
This file contains 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 process = require('process'); | |
const winston = require('winston'); | |
const clc = require('cli-color'); | |
const { | |
TERM = '', | |
LOG_LEVEL = 'info' | |
} = process.env; | |
const colors = ~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, | |
}; | |
const logger = winston.createLogger({ | |
level: LOG_LEVEL, | |
transports: [ | |
new winston.transports.Console({ | |
format: winston.format.combine( | |
winston.format.splat(), | |
winston.format.timestamp(), | |
winston.format.printf( | |
({ level, message, timestamp }) => | |
colors[level](`${timestamp} [${level.toUpperCase()}] ${message}`) | |
), | |
), | |
}), | |
] | |
}); | |
logger.colors = colors; | |
module.exports = logger; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment