[英]How to log Digester with Apache Commons?
I'm having trouble getting Apache Commons Digester to log anything. 我无法让Apache Commons Digester记录任何内容。 I'd be hugely grateful for any light anyone can shed.
我会非常感激任何人都可以流下的光。
In my code I'm 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 commons-logging.properties
file in my classpath as follows: 我在类路径中有一个
commons-logging.properties
文件,如下所示:
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 just get no debug info at all. 我根本没有调试信息。
Thanks for your help! 谢谢你的帮助!
Update : Thanks for the answer bwawok - that's what the problem was. 更新 :感谢答案bwawok - 这就是问题所在。 In the docs for Digester , they suggest that you can just enable the
SimpleLog
of commons-logging. 在Digester的文档中 ,他们建议您只需启用公共日志的
SimpleLog
。 Unfortunately, the Digester
doesn't appear to output any INFO messages, only DEBUG, and at least on eclipse, SimpleLog
doesn't output DEBUG messages at all! 不幸的是,
Digester
似乎没有输出任何INFO消息,只有DEBUG,至少在eclipse上, SimpleLog
根本不输出DEBUG消息! The result was no INFO messages (because Digester
sends none) and no DEBUG messages (because SimpleLog
doesn't forward them!) Once I switched to log4j, all the debug messages came spewing out! 结果是没有INFO消息(因为
Digester
没有发送)并且没有DEBUG消息(因为SimpleLog
不转发它们!)一旦我切换到log4j,所有调试消息都喷涌而出! Thanks again. 再次感谢。
I suggest you don't use commons logging. 我建议你不要使用公共记录。 It has some problems, such as not playing nicely with Tomcat 5.5 and higher.
它有一些问题,比如不能很好地使用Tomcat 5.5及更高版本。
If you are writing your own application (not a library), I suggest you code directly to Log4j. 如果您正在编写自己的应用程序(而不是库),我建议您直接编写Log4j代码。 Read a tutorial at http://logging.apache.org/log4j/1.2/manual.html .
阅读http://logging.apache.org/log4j/1.2/manual.html上的教程。 You will have a log4j.properties file like so
你将有一个像这样的log4j.properties文件
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's 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 instead you are writing a library to distribute (what most people used commons logging for back in the day), look into sl4j. 相反,如果您正在编写一个库来分发(大多数人在当天使用的公共日志记录),请查看sl4j。 http://www.slf4j.org/ .
http://www.slf4j.org/ 。 Most libraries are switching to this instead of commons logging.
大多数库正在切换到此而不是公共日志记录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.