global log level is now set via the log4js object

This commit is contained in:
Alexander Sulfrian 2011-05-30 13:26:30 +02:00
parent a1681f5579
commit d7a97366cb
2 changed files with 13 additions and 12 deletions

View File

@ -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,

View File

@ -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);
}