0

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

| improve this question | | | | |
  • better if you use tomcat virtualhost – c4f4t0r Jun 14 '19 at 22:11
2

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

| improve this answer | | | | |
0

If you add for app1 and app2 in WEB-INF/classes file like log4j.properties and put inside something like:

log4j.appender.logfile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.logfile.DatePattern='.'dd-MM-yyyy
log4j.appender.logfile.File=${catalina.base}/logs/app1.log

(change filename for second app)

you will have in files app1.log and app2.log the output of tomcat for particular app

| improve this answer | | | | |
  • I'm not using log4j but instead basic raw System.out.println for logging. Does your proposed config work also for this in order to divide the output into several files? – tombo_189 May 27 '19 at 18:57
  • @tombo_189, have no idea, maybe will be better to ask in stackoverflow.com – Romeo Ninov May 27 '19 at 19:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.