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) {
|
2019-04-04 20:31:41 +08:00
|
|
|
const env = process.env.NODE_ENV;
|
|
|
|
const logLevel = process.env.LOG_LEVEL;
|
2018-05-23 23:24:48 +08:00
|
|
|
const stream = {
|
2019-04-04 20:31:41 +08:00
|
|
|
level: logLevel ? logLevel : (env === 'test') ? 'fatal' : (env === 'development') ? 'debug' : 'info'
|
2018-05-23 23:24:48 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
if (path) {
|
|
|
|
stream.path = path;
|
|
|
|
} else {
|
|
|
|
stream.stream = process.stdout;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.path = path;
|
|
|
|
this.logger = bunyan.createLogger({
|
|
|
|
name,
|
|
|
|
streams: [stream]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-04-04 20:31:41 +08:00
|
|
|
fatal (...args) {
|
|
|
|
this.logger.fatal(...args);
|
2018-05-23 23:24:48 +08:00
|
|
|
}
|
|
|
|
|
2019-04-04 20:31:41 +08:00
|
|
|
error (...args) {
|
|
|
|
this.logger.error(...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
warn (...args) {
|
|
|
|
this.logger.warn(...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
info (...args) {
|
|
|
|
this.logger.info(...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
debug (...args) {
|
|
|
|
this.logger.debug(...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
trace (...args) {
|
|
|
|
this.logger.trace(...args);
|
2018-05-23 23:24:48 +08:00
|
|
|
}
|
2018-06-19 00:47:12 +08:00
|
|
|
|
|
|
|
reopenFileStreams () {
|
|
|
|
this.logger.reopenFileStreams();
|
|
|
|
}
|
2018-05-23 23:24:48 +08:00
|
|
|
}
|
2019-04-04 20:31:41 +08:00
|
|
|
|
2018-06-08 16:59:34 +08:00
|
|
|
module.exports = Logger;
|