refactor(logger): Refactor logger.js

Use class style implement write interface
This commit is contained in:
BoHong Li 2017-03-19 01:21:43 +08:00 committed by Raccoon Li
parent 90631df2ba
commit 036b2414f3

View file

@ -1,23 +1,23 @@
'use strict' 'use strict'
var winston = require('winston') const winston = require('winston')
winston.emitErrs = true
var logger = new winston.Logger({ class Logger extends winston.Logger {
// Implement stream.writable.write interface
write (chunk) {
this.info(chunk)
}
}
module.exports = new Logger({
transports: [ transports: [
new winston.transports.Console({ new winston.transports.Console({
level: 'debug', level: 'debug',
handleExceptions: true, handleExceptions: true,
json: false, json: false,
colorize: true, colorize: false,
timestamp: true timestamp: true
}) })
], ],
emitErrs: true,
exitOnError: false exitOnError: false
}) })
module.exports = logger
module.exports.stream = {
write: function (message, encoding) {
logger.info(message)
}
}