2018-03-27 21:32:07 +02:00
|
|
|
const logger = require('winston');
|
2018-03-27 21:47:55 +02:00
|
|
|
|
2018-03-27 21:32:07 +02:00
|
|
|
function LoggerConfig () {
|
|
|
|
this.logLevel = 'debug';
|
2018-03-29 21:46:20 +02:00
|
|
|
this.update = (config) => {
|
2018-03-27 21:32:07 +02:00
|
|
|
if (!config) {
|
2018-03-29 21:33:52 +02:00
|
|
|
return logger.warn('No logger config received.');
|
2018-03-27 21:32:07 +02:00
|
|
|
}
|
2018-03-29 21:33:52 +02:00
|
|
|
logger.info('configuring winston logger...');
|
2018-03-27 21:32:07 +02:00
|
|
|
// 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
|
2018-03-29 21:33:52 +02:00
|
|
|
logger.info('testing winston log levels...');
|
2018-05-17 23:42:58 +02:00
|
|
|
logger.warn('Testing: Log Level 1');
|
|
|
|
logger.info('Testing: Log Level 2');
|
|
|
|
logger.verbose('Testing: Log Level 3');
|
|
|
|
logger.debug('Testing: Log Level 4');
|
|
|
|
logger.silly('Testing: Log Level 5');
|
2018-03-27 21:32:07 +02:00
|
|
|
};
|
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();
|