Posts Tagged ‘log4j’

Memo: log4j in tomcat (备忘:Tomcat中配置log4j)

March 9th, 2015

In a tomcat project, we can configure log4j to write logs in a file with:
log4j.appender.rollingFile.File=${catalina.home}/logs/services.log.
This will put all the log files in the /log dir under tomcat root dir.

Here is a full version of the sample log4j.properties.

### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
# log message format: 10:48:40,399 INFO Test:36 - [3, 2, 1]
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
### direct log messages to file ###
log4j.appender.rollingFile=org.apache.log4j.RollingFileAppender
log4j.appender.rollingFile.File=${catalina.home}/logs/services.log
log4j.appender.rollingFile.MaxFileSize=2MB
log4j.appender.rollingFile.MaxBackupIndex=5
log4j.appender.rollingFile.layout = org.apache.log4j.PatternLayout
# log message format: INFO main wp.newsbag.Test - message ...
#log4j.appender.rollingFile.layout.ConversionPattern=%p %t %c - %m%n
log4j.appender.rollingFile.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss,SSS} %5p %c:%L - %m%n
log4j.logger.wp.newsbag=ERROR
#log4j.rootLogger=debug, stdout
log4j.rootLogger=debug, rollingFile