8000 Merge pull request #648 from tmihalcin/logger-initial-configuration · wxqGitHub/log4js-node@796e3bd · GitHub
[go: up one dir, main page]

Skip to content

Commit 796e3bd

Browse files
authored
Merge pull request log4js-node#648 from tmihalcin/logger-initial-configuration
fix: deferred logger configuration.
2 parents 1b67ce1 + d92d885 commit 796e3bd

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lib/log4js.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ function isMaster() {
163163
* @return {Logger} instance of logger for the category
164164
*/
165165
function getLogger(category) {
166+
if (!enabled) {
167+
configure(process.env.LOG4JS_CONFIG || defaultConfig);
168+
}
169+
166170
const cat = category || 'default';
167171
debug(`creating logger as ${isMaster() ? 'master' : 'worker'}`);
168172
return new Logger((isMaster() ? sendLogEventToAppender : workerDispatch), cat);
@@ -285,5 +289,3 @@ const log4js = {
285289
};
286290

287291
module.exports = log4js;
288-
// set ourselves up
289-
configure(process.env.LOG4JS_CONFIG || defaultConfig);

test/tap/configuration-test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ test('log4js configure', (batch) => {
3737
}
3838
};
3939

40-
sandbox.require(
40+
const log4js = sandbox.require(
4141
'../../lib/log4js',
4242
{
4343
requires: {
@@ -46,6 +46,8 @@ test('log4js configure', (batch) => {
4646
}
4747
);
4848

49+
log4js.getLogger('test-logger');
50+
4951
delete process.env.LOG4JS_CONFIG;
5052

5153
t.equal(fileRead, 1, 'should load the specified local config file');

0 commit comments

Comments
 (0)
0