bug 467085 log4moz updateParents messed up, doesn't support multilevel parenting properly, r=thunder

This commit is contained in:
Siddharth Agarwal 2008-12-02 21:42:20 +05:30
Родитель 77c5151401
Коммит 778d86e182
2 изменённых файлов: 24 добавлений и 4 удалений

Просмотреть файл

@ -283,7 +283,9 @@ LoggerRepository.prototype = {
let cur, parent;
// find the closest parent
for (let i = 0; i < pieces.length; i++) {
// don't test for the logger name itself, as there's a chance it's already
// there in this._loggers
for (let i = 0; i < pieces.length - 1; i++) {
if (cur)
cur += '.' + pieces[i];
else
@ -292,15 +294,15 @@ LoggerRepository.prototype = {
parent = cur;
}
// if they are the same it has no parent
if (parent == name)
// if we didn't assign a parent above, there is no parent
if (!parent)
this._loggers[name].parent = this.rootLogger;
else
this._loggers[name].parent = this._loggers[parent];
// trigger updates for any possible descendants of this logger
for (let logger in this._loggers) {
if (logger != name && name.indexOf(logger) == 0)
if (logger != name && logger.indexOf(name) == 0)
this._updateParents(logger);
}
},

Просмотреть файл

@ -24,4 +24,22 @@ function run_test() {
do_check_eq(appender.messages.length, 1);
do_check_true(appender.messages[0].indexOf("info test") > 0);
do_check_true(appender.messages[0].indexOf("INFO") > 0);
// Test - check whether parenting is correct
let grandparentLog = Log4Moz.repository.getLogger("grandparent");
let childLog = Log4Moz.repository.getLogger("grandparent.parent.child");
do_check_eq(childLog.parent.name, "grandparent");
let parentLog = Log4Moz.repository.getLogger("grandparent.parent");
do_check_eq(childLog.parent.name, "grandparent.parent");
// Test - check that appends are exactly in scope
let gpAppender = new MockAppender(new Log4Moz.BasicFormatter());
gpAppender.level = Log4Moz.Level.Info;
grandparentLog.addAppender(gpAppender);
childLog.info("child info test");
log.info("this shouldn't show up in gpAppender");
do_check_eq(gpAppender.messages.length, 1);
do_check_true(gpAppender.messages[0].indexOf("child info test") > 0);
}