开发者

Application is not logging log, how to debug log 4j starting or not

I have created a very simple application, where I am trying to use the Log4J, but my application is not logging any log.

Can anyone please tell me how can I debug the same as my log4j started or not?

I have kept the file in classes folder of WEB-INF/classes

Thanks

following is my 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

following is the sample line for using log 4j..

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


If you're writing a web application, you can view the Log4J Default Initialization Under Tomcat. Even it states Tomcat, the same applies in other Containers/Web application servers.


Console will print this if log4j is not started :

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!

You could have a look at Log4j - Looking for a good 'Getting started' tutorial or blog to get started.

Regards, Stéphane


Make sure the log4j jar is in the lib directory for your webapp or in the lib directory in tomcat. Log4j doesn't seem to work properly for me unless i put the log4j properties file in the default package in the webapp's source directory within the project.

All of my log4j properties files typically look similar to the following

# 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

That's how I do it anyway. There may be a better way but this one always works for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜