1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00
unleash.unleash/lib/logger.js
ivaosthu 1081b9d865 Implement support for logger provider.
This allows the users of 'unleash-server' to programatically
change the logger implemnentation. #175
2017-08-04 16:07:17 +02:00

34 lines
732 B
JavaScript

'use strict';
const log4js = require('log4js');
let loggerProvider = getDefaultLogProvider();
module.exports = exports = function getLogger(name) {
return loggerProvider(name);
};
exports.setLoggerProvider = function setLoggerProvider(provider) {
loggerProvider = provider;
};
function getDefaultLogProvider() {
let level;
if (process.env.NODE_ENV === 'production') {
level = log4js.levels.ERROR;
} else if (process.env.NODE_ENV === 'test') {
level = log4js.levels.FATAL;
} else {
level = log4js.levels.DEBUG;
}
log4js.configure({
appenders: [{ type: 'console' }],
levels: {
'[all]': level,
},
});
return log4js.getLogger;
}