Last Updated: February 25, 2016
·
894
· jan0sch

Log to file using log4j when running with tomcat

In case you have an application running under tomcat and want to write your logs to a seperate file using log4j you can use some variables that tomcat is setting up.

Therefore you can use a path like ${catalina.home}/logs/... in your log4j.properties:

log4j.rootLogger=INFO, FileLogger
log4j.appender.FileLogger=org.apache.log4j.RollingFileAppender
log4j.appender.FileLogger.File=${catalina.home}/logs/MY_OWN_LOGFILE.log
log4j.appender.FileLogger.MaxFileSize=10MB
log4j.appender.FileLogger.MaxBackupIndex=10
log4j.appender.FileLogger.layout=org.apache.log4j.PatternLayout
log4j.appender.FileLogger.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %c: %m%n