2018-03-27 21:32:07 +02:00
|
|
|
const logger = require('winston');
|
|
|
|
function LoggerConfig () {
|
|
|
|
this.logLevel = 'debug';
|
|
|
|
this.configure = (config) => {
|
|
|
|
if (!config) {
|
|
|
|
return console.log('No logger config received.');
|
|
|
|
}
|
|
|
|
// update values with local config params
|
|
|
|
const {logLevel} = config;
|
|
|
|
this.logLevel = logLevel;
|
|
|
|
// configure the winston logger
|
|
|
|
logger.configure({
|
|
|
|
transports: [
|
|
|
|
new (logger.transports.Console)({
|
|
|
|
level : this.logLevel,
|
|
|
|
timestamp : false,
|
|
|
|
colorize : true,
|
|
|
|
prettyPrint : true,
|
|
|
|
handleExceptions : true,
|
|
|
|
humanReadableUnhandledException: true,
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
});
|
|
|
|
// test all the log levels
|
|
|
|
logger.error('Level 0');
|
|
|
|
logger.warn('Level 1');
|
|
|
|
logger.info('Level 2');
|
|
|
|
logger.verbose('Level 3');
|
|
|
|
logger.debug('Level 4');
|
|
|
|
logger.silly('Level 5');
|
|
|
|
};
|
2017-06-19 22:10:06 +02:00
|
|
|
};
|
2018-03-10 01:45:24 +01:00
|
|
|
|
2018-03-27 21:32:07 +02:00
|
|
|
module.exports = new LoggerConfig();
|