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
|
|
|
|
2019-04-19 18:14:03 +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: [
|
2019-04-19 18:14:03 +02:00
|
|
|
new logger.transports.Console({
|
|
|
|
level: logLevel || 'debug',
|
|
|
|
timestamp: true,
|
|
|
|
colorize: true,
|
|
|
|
prettyPrint: true,
|
|
|
|
handleExceptions: true,
|
2018-06-06 03:55:44 +02:00
|
|
|
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;
|