应用程序不是日志记录,如何调试log 4j启动与否

时间:2011-08-31 13:39:39

标签: java log4j

我创建了一个非常简单的应用程序,我尝试使用Log4J,但我的应用程序没有记录任何日志。

任何人都可以告诉我如何调试我的log4j启动与否?

我将文件保存在WEB-INF/classes

的类文件夹中

由于

以下是我的log4j.properties

log4j.rootLogger=debug, stdout, ABC

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.ABC=org.apache.log4j.RollingFileAppender
log4j.appender.ABC.File=D://abc//dams_workflow_application.log

log4j.appender.ABC.MaxFileSize=3000KB
# Keep one backup file
log4j.appender.ABC.MaxBackupIndex=10

log4j.appender.ABC.layout=org.apache.log4j.PatternLayout
log4j.appender.ABC.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n

以下是使用log 4j的示例行..

 Logger log = Logger.getLogger("ABC");
 log.info("my message");

3 个答案:

答案 0 :(得分:1)

如果您正在编写Web应用程序,则可以查看Log4J Default Initialization Under Tomcat。即使它声明了Tomcat,在其他容器/ Web应用程序服务器中也是如此。

答案 1 :(得分:0)

如果未启动log4j,控制台将打印此文件:

log4j:WARN No log4j configuration information found.
log4j:WARN Changed non-configured level from DEBUG to ERROR.
log4j:WARN The log4j system is not properly configured!

你可以查看Log4j - Looking for a good 'Getting started' tutorial or blog 开始。

此致  斯特凡

答案 2 :(得分:0)

确保log4j jar位于webapp的lib目录中或tomcat中的lib目录中。 除非我将log4j属性文件放在项目中webapp的源目录中的默认包中,否则Log4j似乎对我不起作用。

我的所有log4j属性文件通常类似于以下

# Define a logger called "processLog" using the FileAppender implementation of the
# Log interface
log4j.appender.processLog=org.apache.log4j.DailyRollingFileAppender
log4j.appender.processLog.File.DateFormat='.'yyyy-ww

# Define the output location
log4j.appender.processLog.File=C:/logs/myapp.log

# Define what the output is going to look like for your log
log4j.appender.processLog.layout=org.apache.log4j.PatternLayout
log4j.appender.processLog.layout.ConversionPattern=%d{yyyy-MM-dd hh:mm a} %5p %c{1}: Line#%L - %m%n

# log4j.rootLogger specifies the default logging level and output location.
# The first parameter is the level (debug > info > warn > error > fatal).
log4j.rootLogger=INFO, processLog

无论如何我就是这样做的。可能有更好的方法,但这个对我来说总是有效。