Merge pull request #648 from tmihalcin/logger-initial-configuration

fix: deferred logger configuration.
This commit is contained in:
Gareth Jones 2018-01-17 08:11:59 +11:00 committed by GitHub
commit 796e3bd731
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View File

@ -163,6 +163,10 @@ function isMaster() {
* @return {Logger} instance of logger for the category
*/
function getLogger(category) {
if (!enabled) {
configure(process.env.LOG4JS_CONFIG || defaultConfig);
}
const cat = category || 'default';
debug(`creating logger as ${isMaster() ? 'master' : 'worker'}`);
return new Logger((isMaster() ? sendLogEventToAppender : workerDispatch), cat);
@ -285,5 +289,3 @@ const log4js = {
};
module.exports = log4js;
// set ourselves up
configure(process.env.LOG4JS_CONFIG || defaultConfig);

View File

@ -37,7 +37,7 @@ test('log4js configure', (batch) => {
}
};
sandbox.require(
const log4js = sandbox.require(
'../../lib/log4js',
{
requires: {
@ -46,6 +46,8 @@ test('log4js configure', (batch) => {
}
);
log4js.getLogger('test-logger');
delete process.env.LOG4JS_CONFIG;
t.equal(fileRead, 1, 'should load the specified local config file');