[jsword-devel] Replacing log4j

DM Smith dmsmith555 at yahoo.com
Sun Sep 19 14:47:23 MST 2004


Well I have taken a look at replacing log4j with Java's logger. The goal 
is to make common as light as possible (wrt to dependencies on outside 
jars) so that other projects would not hesitate to use it.

It looked like it was a pretty simple change, but there is a snag. It 
does not properly report the location of the logging.

First let me describe how the two map to each other:
Both have the same notion of getting a logger named via the class name:
log4j is Logger.getLogger(Class clazz)
java is Logger.getLogger(String classname)

Both have predefined levels in a Level class.
log4j: FATAL,ERROR,WARN,INFO,DEBUG
java: SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST
and both have convienence functions for these methods. I see mapping 
them from left to right and not using FINER and FINEST.

Both have:
    the same notion of inheritance of logging
    the same notion of a root logger
    the same notion of configuration by a properties file
    the ability to set the global logging level

Differences:
log4j allows for a Throwable to be passed into the convienence methods 
(e.g. log.warn("message", throwable) and it appends it to the message.)
java requires the use of logger.log(Level.WARNING, "message", throwable)

log4j can be wrapped and produce class, method and line of the caller. 
Java's logger does not dig into the stack trace to determine the nearest 
match to the logger's class.
    Solution: in the wrapper get the stack trace and figure out the 
calling class, method and line. Not very easy but can be done.

log4j writes to stdout, while java writes to stderr. This is 
configurable in log4j and I think in java. My opinion is that stderr is 
better as it is not buffered.

log4j has single line output, java has 2 line output. This is 
configurable in log4j and I think in java.

I am going to check in the change to .../common/util/Logger.java so you 
can see the differences. I handled the stack trace.

Given our use of log4j, I don't see any advantage of it over Java's logger.

My recommendation is to migrate to Java's logger directly and not 
wrapped (as opposed to solving the wrapping problem).

I'll be looking into configuring the logger to mimic the output of log4j.




More information about the jsword-devel mailing list