Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Global Log level #176

Merged
merged 4 commits into from

3 participants

@RolfKoenders

Set the global level via the configuration object passed to log4js.configure or target all in the levels object.
#87

@nomiddlename nomiddlename merged commit 8cf0350 into from
@nomiddlename

Hi, I was reluctant to merge this because travis was telling me it broke the build. Tried it locally, all seems fine. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 21, 2014
  1. @Rolfje

    Set the global level via the configuration object passed to

    Rolfje authored
    log4js.configure or target `all` in the `levels` object.
Commits on Jan 22, 2014
  1. @Rolfje
Commits on Jan 23, 2014
  1. @RolfKoenders

    Update log4js.js

    RolfKoenders authored
    Overlooked that there was already a var with '[all]'.
Commits on May 4, 2014
  1. @RolfKoenders
This page is out of date. Refresh to see the latest.
Showing with 50 additions and 12 deletions.
  1. +3 −0  lib/log4js.js
  2. +47 −12 test/global-log-level-test.js
View
3  lib/log4js.js
@@ -166,6 +166,9 @@ function configureLevels(levels) {
if (levels) {
for (var category in levels) {
if (levels.hasOwnProperty(category)) {
+ if(category === ALL_CATEGORIES) {
+ setGlobalLogLevel(levels[category]);
+ }
getLogger(category).setLevel(levels[category]);
}
}
View
59 test/global-log-level-test.js
@@ -8,7 +8,7 @@ vows.describe('log4js global loglevel').addBatch({
var log4js = require('../lib/log4js');
return log4js;
},
-
+
'set global loglevel on creation': function(log4js) {
var log1 = log4js.getLogger('log1');
var level = 'OFF';
@@ -16,14 +16,14 @@ vows.describe('log4js global loglevel').addBatch({
level = 'TRACE';
}
assert.notEqual(log1.level.toString(), level);
-
+
log4js.setGlobalLogLevel(level);
assert.equal(log1.level.toString(), level);
var log2 = log4js.getLogger('log2');
assert.equal(log2.level.toString(), level);
},
-
+
'global change loglevel': function(log4js) {
var log1 = log4js.getLogger('log1');
var log2 = log4js.getLogger('log2');
@@ -32,7 +32,7 @@ vows.describe('log4js global loglevel').addBatch({
level = 'TRACE';
}
assert.notEqual(log1.level.toString(), level);
-
+
log4js.setGlobalLogLevel(level);
assert.equal(log1.level.toString(), level);
assert.equal(log2.level.toString(), level);
@@ -46,20 +46,20 @@ vows.describe('log4js global loglevel').addBatch({
level = 'TRACE';
}
assert.notEqual(log1.level.toString(), level);
-
+
var oldLevel = log1.level.toString();
assert.equal(log2.level.toString(), oldLevel);
-
+
log2.setLevel(level);
assert.equal(log1.level.toString(), oldLevel);
assert.equal(log2.level.toString(), level);
assert.notEqual(oldLevel, level);
-
+
log2.removeLevel();
assert.equal(log1.level.toString(), oldLevel);
assert.equal(log2.level.toString(), oldLevel);
},
-
+
'preload loglevel': function(log4js) {
var log1 = log4js.getLogger('log1');
var level = 'OFF';
@@ -67,20 +67,55 @@ vows.describe('log4js global loglevel').addBatch({
level = 'TRACE';
}
assert.notEqual(log1.level.toString(), level);
-
+
var oldLevel = log1.level.toString();
log4js.getLogger('log2').setLevel(level);
-
+
assert.equal(log1.level.toString(), oldLevel);
-
+
// get again same logger but as different variable
var log2 = log4js.getLogger('log2');
assert.equal(log2.level.toString(), level);
assert.notEqual(oldLevel, level);
-
+
log2.removeLevel();
assert.equal(log1.level.toString(), oldLevel);
assert.equal(log2.level.toString(), oldLevel);
+ },
+
+ 'set level on all categories': function(log4js) {
+ // Get 2 loggers
+ var log1 = log4js.getLogger('log1');
+ var log2 = log4js.getLogger('log2');
+
+ // First a test with 2 categories with different levels
+ var config = {
+ 'levels': {
+ 'log1': 'ERROR',
+ 'log2': 'WARN'
+ }
+ };
+ log4js.configure(config);
+
+ // Check if the levels are set correctly
+ assert.equal('ERROR', log1.level.toString());
+ assert.equal('WARN', log2.level.toString());
+
+ log1.removeLevel();
+ log2.removeLevel();
+
+ // Almost identical test, but now we set
+ // level on all categories
+ var config2 = {
+ 'levels': {
+ '[all]': 'DEBUG'
+ }
+ };
+ log4js.configure(config2);
+
+ // Check if the loggers got the DEBUG level
+ assert.equal('DEBUG', log1.level.toString());
+ assert.equal('DEBUG', log2.level.toString());
}
}
}).export(module);
Something went wrong with that request. Please try again.