2018-05-23 23:24:48 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const bunyan = require('bunyan');
|
|
|
|
|
2018-06-08 16:59:34 +08:00
|
|
|
class Logger {
|
2018-05-23 23:24:48 +08:00
|
|
|
constructor (path, name) {
|
|
|
|
const stream = {
|
|
|
|
level: process.env.NODE_ENV === 'test' ? 'fatal' : 'info'
|
|
|
|
};
|
|
|
|
|
|
|
|
if (path) {
|
|
|
|
stream.path = path;
|
|
|
|
} else {
|
|
|
|
stream.stream = process.stdout;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.path = path;
|
|
|
|
this.logger = bunyan.createLogger({
|
|
|
|
name,
|
|
|
|
streams: [stream]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
info (log, message) {
|
|
|
|
this.logger.info(log, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
warn (log, message) {
|
|
|
|
this.logger.warn(log, message);
|
|
|
|
}
|
2018-06-19 00:47:12 +08:00
|
|
|
|
|
|
|
reopenFileStreams () {
|
|
|
|
console.log('Reloading log file', this.path);
|
|
|
|
this.logger.reopenFileStreams();
|
|
|
|
}
|
2018-05-23 23:24:48 +08:00
|
|
|
}
|
|
|
|
|
2018-06-08 16:59:34 +08:00
|
|
|
module.exports = Logger;
|