2020-06-02 17:49:54 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const pino = require('pino');
|
|
|
|
|
|
|
|
module.exports = class Logger {
|
|
|
|
constructor () {
|
|
|
|
const { LOG_LEVEL, NODE_ENV } = process.env;
|
2020-06-02 19:16:26 +08:00
|
|
|
const logLevelFromNodeEnv = NODE_ENV === 'test' ? 'fatal' : 'info';
|
2020-06-02 17:49:54 +08:00
|
|
|
const options = {
|
|
|
|
base: null, // Do not bind hostname, pid and friends by default
|
2020-06-02 19:16:26 +08:00
|
|
|
level: LOG_LEVEL || logLevelFromNodeEnv
|
2020-06-02 17:49:54 +08:00
|
|
|
};
|
2020-06-02 19:16:26 +08:00
|
|
|
const dest = pino.destination({ sync: false }); // stdout
|
2020-06-02 17:49:54 +08:00
|
|
|
|
|
|
|
this._logger = pino(options, dest);
|
|
|
|
}
|
|
|
|
|
|
|
|
trace (...args) {
|
|
|
|
this._logger.trace(...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
debug (...args) {
|
|
|
|
this._logger.debug(...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
info (...args) {
|
|
|
|
this._logger.info(...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
warn (...args) {
|
|
|
|
this._logger.warn(...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
error (...args) {
|
|
|
|
this._logger.error(...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
fatal (...args) {
|
|
|
|
this._logger.fatal(...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
child (...args) {
|
|
|
|
return this._logger.child(...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
finish (callback) {
|
|
|
|
return pino.final(this._logger, callback);
|
|
|
|
}
|
|
|
|
};
|