您的位置:首页 > 其它

With commons loggin and Log4j, the TRACE level is replaced with DEBUG level.

2008-05-20 20:11 513 查看
Recently, when I was using the commons logging 1.0.4 and log4j 1.2.13, I found the log level TRACE is replaced with DEBUG. Then I trace into the codes, I found the Apache commons logging has the TRACE level earlier than log4j. So when it process the trace level, it will send the TRACE message to log4j with DEBUG level. Please update to the latest packages for both commons loggin and log4j. Please see the relative codes.

Please see the codes in Log4JLogger.java in version commons loggin 1.0.4

public void trace(Object message) {
if(is12) {
getLogger().log(FQCN, (Priority) Level.DEBUG, message, null );
} else {
getLogger().log(FQCN, Level.DEBUG, message, null );
}
}

Please see the codes in Log4JLogger.java in version commons loggin 1.1

static {
if (!Priority.class.isAssignableFrom(Level.class)) {
// nope, this is log4j 1.3, so force an ExceptionInInitializerError
throw new InstantiationError("Log4J 1.2 not available");
}

// Releases of log4j1.2 >= 1.2.12 have Priority.TRACE available, earlier
// versions do not. If TRACE is not available, then we have to map
// calls to Log.trace(...) onto the DEBUG level.

try {
traceLevel = (Priority) Level.class.getDeclaredField("TRACE").get(null);
} catch(Exception ex) {
// ok, trace not available
traceLevel = Priority.DEBUG;
}
}

public void trace(Object message, Throwable t) {
if(is12) {
getLogger().log(FQCN, (Priority) Level.DEBUG, message, t );
} else {
getLogger().log(FQCN, Level.DEBUG, message, t );
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐