Nitesh singh
Nitesh singh

Reputation: 5

How to write unique log file for each instance of tomcat server?

There are two instances i.e. lisxyz and lisabc and webapplication deployed on them points to same file mount to write the log file. How could I generate log file for each of these instance i.e. something like log_lisxyz_{timestamp}.log - which contains only lisxyz-specific logs and log_lisabc_{timestamp}.log for lisabc-specific logs.

Which approach (default tomcat internal logging- JULI or log4j) is suitable and has more control ?

Upvotes: 0

Views: 632

Answers (1)

jmehrens
jmehrens

Reputation: 11045

How could I generate log file for each of these instance

Per Tomcat JULI you can place a logging.properties in WEB-INF/classes:

handlers = org.apache.juli.FileHandler

############################################################
# 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 = ${classloader.webappName}_.

By default the org.apache.juli.FileHandler will add the timestamp after the prefix but before the suffix.

Which approach (default tomcat internal logging- JULI or log4j) is suitable and has more control ?

Log4j is covered in the Tomcat documentation too. It will have more support for date patterns in the file name. I would think that either would work for the requirements given.

Upvotes: 1

Related Questions