Tomcat – How to Configure Separate catalina.out Logs for Each WAR

loggingtomcat

I've a tomcat 8.5 instance running with several WAR's deployed, each of them writing its internal output via System.out to console.

Now, tomcat combines all this log outputs together in one file: catalina.out, but I would like to separate them. Is it possible to configure tomcat's logging properties to create different catalina.outs on a per-WAR-base, e.g.

  • console output of app1.war -> catalina-app1.out
  • console output of app2.war -> catalina-app2.out

Thanx
Tom

Best Answer

put "swallowOutput" in your context.xml

<Context swallowOutput="true">
...
</Context>

and add an individual logging.properties file into each of your webapps/wars at the position

/WEB-INF/classes/logging.properties

You can put this file also in the source-folder if your WAR is generated, e.g. by eclipse

/src/logging.properties

The logging.properties may have the following contents

  handlers = org.apache.juli.FileHandler, java.util.logging.ConsoleHandler

############################################################
# Handler specific properties.
# Describes specific configuration info for Handlers.
############################################################

org.apache.juli.FileHandler.level = FINE
org.apache.juli.FileHandler.directory = ${catalina.base}/logs
org.apache.juli.FileHandler.prefix = webapp_name.

java.util.logging.ConsoleHandler.level = FINE

java.util.logging.ConsoleHandler.formatter = java.util.logging.OneLineFormatter

and you can define the name prefix for each individual webapp log with org.apache.juli.FileHandler.prefix