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
Written by Jens Grassel
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Tomcat
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#