`

With commons loggin and Log4j, the TRACE level is

阅读更多

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

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics