As promised, I've changed the way the logger is fetched in the PDF
library and the font code. Instead of passing a Log instance from parent
to child (IoC, like with Avalon), logging-enabled classes fetch their
own logger via JCL's LogFactory. The code gets easier. I'm quite happy
with this.

As you may have seen I added a cvsignore file in the src directory. The
idea is to put a simplelog.properties (or other such configuration file) in
the src/private-resources directory so you can configure the SimpleLog
logger from Commons Logging.

My current simplelog.properties looks like this:
org.apache.commons.logging.simplelog.showShortLogname=false
org.apache.commons.logging.simplelog.defaultlog=info
org.apache.commons.logging.simplelog.log.org.apache.fop.pdf=trace

Info about simplelog.properties can be found at [1].

One additional thing is to add a system property to each startup
configuration in your IDE where you need to configure logging. Working
with Eclipse I've added...

-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog

...to the "VM arguments" in the run configuration. This ensures that
Commons Logging will not use JDK 1.4 logging (see [2]), but directly
choose the SimpleLog implementation which is sufficient while developing.
Of course, you can use JDK 1.4 loggging or Log4J, as you wish. See the
javadocs for LogFactoryImpl [2] for further information. The whole
documentation on Commons Logging is available at it homepage [3].

[1] 
http://jakarta.apache.org/commons/logging/api/org/apache/commons/logging/impl/SimpleLog.html
[2] 
http://jakarta.apache.org/commons/logging/api/org/apache/commons/logging/impl/LogFactoryImpl.html
[3] http://jakarta.apache.org/commons/logging/


For setting up Commons Logging for a command-line application, please
see PFMReader and TTFReader for how I think it should be done. I'm not
entirely comfortable, yet, as SimpleLog logs everything to System.err.
For Barcode4J I wrote a special ConsoleLogger (for Avalon Logging) [4] that
logs only WARN, ERROR and FATAL levels to System.err while sending the
rest to System.out. Also, there's no possibility to get rid of the log
level prefix in SimpleLog. In the end, it would probably be best to
create a special CommandLineLog class which is tailored to this use case.

[4] 
http://cvs.sourceforge.net/viewcvs.py/barcode4j/barcode4j/src/java/org/krysalis/barcode4j/cli/AdvancedConsoleLogger.java?rev=1.1&view=auto

Jeremias Maerki

Reply via email to