How to configure logging for a Tomcat application to a separate log file?

Created:

2016-12-12 03:46:45 UTC

Modified:

2017-04-24 11:23:47 UTC

0

Was this article helpful?


Have more questions?

Submit a request

How to configure logging for a Tomcat application to a separate log file?

Applicable to:

  • Plesk 12.5 for Linux
  • Plesk 12.5 for Windows

Question

How to configure logging for a Tomcat application to a separate log file?

Resolution

For Tomcat 4 :

Add Logger to "Host/Context" section in /etc/tomcat4/server.xml :

<Logger className="org.apache.catalina.logger.FileLogger" prefix="example.com\\_appname\\_log." suffix=".txt" timestamp="true">

For example, logging directives for the appname application on example.com should look like the following:

<Host name="**example.com**" debug="0" appBase="webapps" unpackWARs="true">

<Context path="/**appname**" docBase="**appname**" debug="0" reloadable="true">

<Logger className="org.apache.catalina.logger.FileLogger" prefix="**domain.com\\_examples\\_log**." suffix=".txt" timestamp="true">

</Context>

</Host>

After that, the appname application for domain example.com will write the log to example.com\\_appname\\_log.\\* files.

Please refer to the following resource for details: http://www.onjava.com/pub/a/onjava/2002/07/31/tomcat.html?page=1

For Tomcat 7 :

The correct notation in /etc/tomcat7/server.xml is the following:

<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="example.com_app_access_log." suffix=".txt" pattern="%h %l %u %t &quot;%r&quot; %s %b" />

Please refer to the following resource for details: http://www.ntu.edu.sg/home/ehchua/programming/howto/tomcat_more.html

Additional information

http://stackoverflow.com/questions/15750564/application-specific-log-in-tomcat-7-using-juli
http://coderanch.com/t/659149/configure-log-tomcat
http://tomcat.apache.org/tomcat-7.0-doc/logging.html 'Using Log4j' section

Have more questions? Submit a request
Please sign in to leave a comment.