From d7a97366cb5a13a10e36910c4f12d0b2680ec435 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Mon, 30 May 2011 13:26:30 +0200 Subject: [PATCH] global log level is now set via the log4js object --- lib/log4js.js | 13 +++++++------ test/test-global-log-level.js | 12 ++++++------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/log4js.js b/lib/log4js.js index 46e7bab..6ef64db 100644 --- a/lib/log4js.js +++ b/lib/log4js.js @@ -267,20 +267,16 @@ function Logger (name, level) { this.category = name || DEFAULT_CATEGORY; if (! this.level) { - this.setLevel('TRACE'); + this.__proto__.level = levels.TRACE; } } sys.inherits(Logger, events.EventEmitter); Logger.prototype.setLevel = function(level) { - this.__proto__.level = Level.toLevel(level, levels.TRACE); -}; - -Logger.prototype.setLocalLevel = function(level) { this.level = Level.toLevel(level, levels.TRACE); }; -Logger.prototype.removeLocalLevel = function() { +Logger.prototype.removeLevel = function() { delete this.level; }; @@ -308,6 +304,10 @@ Logger.prototype.isLevelEnabled = function(otherLevel) { } ); +function setGlobalLogLevel(level) { + Logger.prototype.level = Level.toLevel(level, levels.TRACE); +} + /** * Get the default logger instance. * @return {Logger} instance of default logger @@ -672,6 +672,7 @@ module.exports = function (fileSystem, standardOutput, configPaths) { configure: configure, levels: levels, + setGlobalLogLevel: setGlobalLogLevel, consoleAppender: consoleAppender, fileAppender: fileAppender, diff --git a/test/test-global-log-level.js b/test/test-global-log-level.js index 39ea432..8616597 100644 --- a/test/test-global-log-level.js +++ b/test/test-global-log-level.js @@ -16,7 +16,7 @@ vows.describe('log4js global loglevel').addBatch({ } assert.notEqual(log1.level.toString(), level); - log1.setLevel(level); + log4js.setGlobalLogLevel(level); assert.equal(log1.level.toString(), level); var log2 = log4js.getLogger('log2'); @@ -32,7 +32,7 @@ vows.describe('log4js global loglevel').addBatch({ } assert.notEqual(log1.level.toString(), level); - log1.setLevel(level); + log4js.setGlobalLogLevel(level); assert.equal(log1.level.toString(), level); assert.equal(log2.level.toString(), level); }, @@ -49,12 +49,12 @@ vows.describe('log4js global loglevel').addBatch({ var oldLevel = log1.level.toString(); assert.equal(log2.level.toString(), oldLevel); - log2.setLocalLevel(level); + log2.setLevel(level); assert.equal(log1.level.toString(), oldLevel); assert.equal(log2.level.toString(), level); assert.notEqual(oldLevel, level); - log2.removeLocalLevel(); + log2.removeLevel(); assert.equal(log1.level.toString(), oldLevel); assert.equal(log2.level.toString(), oldLevel); }, @@ -68,7 +68,7 @@ vows.describe('log4js global loglevel').addBatch({ assert.notEqual(log1.level.toString(), level); var oldLevel = log1.level.toString(); - log4js.getLogger('log2').setLocalLevel(level); + log4js.getLogger('log2').setLevel(level); assert.equal(log1.level.toString(), oldLevel); @@ -77,7 +77,7 @@ vows.describe('log4js global loglevel').addBatch({ assert.equal(log2.level.toString(), level); assert.notEqual(oldLevel, level); - log2.removeLocalLevel(); + log2.removeLevel(); assert.equal(log1.level.toString(), oldLevel); assert.equal(log2.level.toString(), oldLevel); }