Ruslan
Ruslan

Reputation: 2009

Tomcat log each application into separate file

Right now we have 3 applications that run on tomcat. All the logging is combined in the localhost-2017-03-01.log file. Is there a way to log each application to their own log?

It's getting difficult to debug when all the output is combined

Upvotes: 4

Views: 4645

Answers (1)

Richard Osseweyer
Richard Osseweyer

Reputation: 1744

You can put a log4j.properties file in the WEB-INF/classes directory of each application. Then you can configure logging on a per-app basis:

...
# Set up a logger to a log file
log4j.appender.logfile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.logfile.DatePattern='.'yyyy-MM-dd
log4j.appender.logfile.File=${catalina.base}/logs/my_application.log
...

where my_application.log is the unique file name you want the log files for this application to be written to. In this example the log files are rolled over after a day, so they get the date appended to the filename. (Actually there's pretty much you can configure, you could even tell log4j to send you e-mails for messages above a certain threshold.)

Upvotes: 4

Related Questions