How do I register Digester with Apache Commons?
I am having trouble getting Apache Commons Digester to register anything. I would be very grateful for any light that anyone can lose.
In my code, I am doing this:
Digester digester = new Digester();
// some Digester set up stuff
// What on earth should go in here????
digester.setLogger(LogFactory.getLog("org.apache.commons.logging.Log"));
I have a file commons-logging.properties
in my classpath like this:
org.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog
org.apache.commons.logging.simplelog.log.org.apache.commons.digester.Digester=debug
org.apache.commons.logging.simplelog.log.org.apache.commons.digester.Digester.sax=info
I am not getting any debug information at all.
Thanks for your help!
Update: Thanks for the answer bwawok - that was the problem. In the docs for Digester , they suggest that you simply enable SimpleLog
public record keeping. Unfortunately it Digester
does not output any INFO messages, only DEBUG and, at least on eclipse, SimpleLog
does not output any DEBUG messages at all! As a result, there were no INFO messages (because it Digester
doesn't send any) and no DEBUG messages (because it SimpleLog
doesn't forward them!) After I switched to log4j, all debug messages are out of order! Thanks again.
a source to share
I suggest that you do not use the community entry. It has some problems like not playing nicely with Tomcat 5.5 and up.
If you are writing your own application (not a library), I suggest you code directly in Log4j. Read the tutorial at http://logging.apache.org/log4j/1.2/manual.html . You will have a log4j.properties file similar to
log4j.rootLogger=debug, stdout, R
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
# Pattern to output the caller file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=example.log
log4j.appender.R.MaxFileSize=100KB
# Keep one backup file
log4j.appender.R.MaxBackupIndex=1
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
Then in your application, you would use
Logger logger = Logger.getLogger(MyClassName.class);
logger.info("Doing something I want to log at info... " );
logger.warn("Danger!");
If you are writing a distribution library instead (which is what most people used to do public record keeping throughout the day), look at sl4j. http://www.slf4j.org/ . Most libraries switch to this rather than writing to communities.
a source to share