Be able to set log level from env variable LOG_LEVEL

This commit is contained in:
Daniel García Aubert 2020-06-02 13:16:26 +02:00
parent b60116410a
commit b7b3392bdd

View File

@ -5,11 +5,12 @@ const pino = require('pino');
module.exports = class Logger {
constructor () {
const { LOG_LEVEL, NODE_ENV } = process.env;
const logLevelFromNodeEnv = NODE_ENV === 'test' ? 'fatal' : 'info';
const options = {
base: null, // Do not bind hostname, pid and friends by default
level: LOG_LEVEL || NODE_ENV === 'test' ? 'fatal' : 'info'
level: LOG_LEVEL || logLevelFromNodeEnv
};
const dest = pino.destination({ sync: false });
const dest = pino.destination({ sync: false }); // stdout
this._logger = pino(options, dest);
}