Use winston

This commit is contained in:
Ibby Hadeed
2017-12-28 23:15:34 -05:00
parent a26457b30a
commit 1c35991548
8 changed files with 88 additions and 14 deletions
+24
View File
@@ -0,0 +1,24 @@
import * as winston from 'winston';
import { isEmpty } from 'lodash';
const LOG_LEVEL = 'debug';
export const Logger = new winston.Logger({
level: LOG_LEVEL,
transports: [
new winston.transports.Console({
level: 'debug',
formatter: (opts: any) => {
if (opts.meta) {
if (typeof opts.meta['durationMs'] === 'number') {
opts.message += ' ' + opts.meta['durationMs'] + 'ms';
delete opts.meta['durationMs'];
}
if (!isEmpty(opts.meta)) console.log(opts.meta);
}
return winston.config.colorize(opts.level, opts.level.toUpperCase()) + ' ' + opts.message;
}
})
]
});