2018-06-06 03:55:44 +02:00
|
|
|
const logger = require('winston');
|
|
|
|
|
2018-06-06 21:01:11 +02:00
|
|
|
const config = require('@config/loggerConfig');
|
|
|
|
const { logLevel } = config;
|
2018-06-06 03:55:44 +02:00
|
|
|
|
|
|
|
function configureLogging () {
|
2018-06-06 21:01:11 +02:00
|
|
|
logger.info('configuring winston logger...');
|
|
|
|
if (!config) {
|
|
|
|
return logger.warn('No logger config found');
|
|
|
|
}
|
2018-06-06 03:55:44 +02:00
|
|
|
if (!logLevel) {
|
2018-06-06 21:01:11 +02:00
|
|
|
logger.warn('No logLevel found in config.');
|
2018-06-06 03:55:44 +02:00
|
|
|
}
|
|
|
|
// configure the winston logger
|
|
|
|
logger.configure({
|
|
|
|
transports: [
|
|
|
|
new (logger.transports.Console)({
|
2018-06-06 21:01:11 +02:00
|
|
|
level : logLevel || 'debug',
|
2018-06-06 03:55:44 +02:00
|
|
|
timestamp : false,
|
|
|
|
colorize : true,
|
|
|
|
prettyPrint : true,
|
|
|
|
handleExceptions : true,
|
|
|
|
humanReadableUnhandledException: true,
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
});
|
|
|
|
// test all the log levels
|
|
|
|
logger.info('testing winston log levels...');
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = configureLogging;
|