8000 Merge pull request #770 from log4js-node/config-level-serialisation · lianxuify/log4js-node@1d6c0a3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1d6c0a3

Browse files
authored
Merge pull request log4js-node#770 from log4js-node/config-level-serialisation
fix(log4js-node#768): allow config to use level objects
2 parents 07e3b0b + 8276086 commit 1d6c0a3

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

lib/levels.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ class Level {
3434
return sArg;
3535
}
3636

37+
// a json-serialised level won't be an instance of Level (see issue #768)
38+
if (sArg instanceof Object && sArg.levelStr) {
39+
sArg = sArg.levelStr;
40+
}
41+
3742
if (typeof sArg === 'string') {
3843
return Level[sArg.toUpperCase()] || defaultLevel;
3944
}

test/tap/configuration-validation-test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,5 +337,13 @@ test('log4js configuration validation', (batch) => {
337337
t.end();
338338
});
339339

340+
batch.test('should not give error if level object is used instead of string', (t) => {
341+
t.doesNotThrow(() => log4js.configure({
342+
appenders: { thing: { type: 'stdout' } },
343+
categories: { default: { appenders: ['thing'], level: log4js.levels.ERROR } }
344+
}));
345+
t.end();
346+
});
347+
340348
batch.end();
341349
});

test/tap/levels-test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,12 +377,13 @@ test('levels', (batch) => {
377377
t.end();
378378
});
379379

380-
batch.test('toLevel', (t) => {
380+
batch.test('getLevel', (t) => {
381381
t.equal(levels.getLevel('debug'), levels.DEBUG);
382382
t.equal(levels.getLevel('DEBUG'), levels.DEBUG);
383383
t.equal(levels.getLevel('DeBuG'), levels.DEBUG);
384384
t.notOk(levels.getLevel('cheese'));
385385
t.equal(levels.getLevel('cheese', levels.DEBUG), levels.DEBUG);
386+
t.equal(levels.getLevel({ level: 10000, levelStr: 'DEBUG', colour: 'cyan' }), levels.DEBUG);
386387
t.end();
387388
});
388389

0 commit comments

Comments
 (0)
0