Posted almost 6 years ago. Visible to the public.

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:

Copy
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

Owner of this card:

Avatar
jan0sch
Last edit:
almost 6 years ago
Posted by jan0sch to jan0sch's deck
This website uses cookies to improve usability and analyze traffic.
Accept or learn more