Tomcat 7- Change location of log files

Viewed 16148

I am running tomcat7 on ubuntu 14.04. I need to change the folder location for the log file: /var/log/tomcat7/catalina.out

I tried the following:

  1. Set environment variable CATALINA_OUT in the /etc/environment file to my custom location: CATALINA_OUT=/xyz/catalina.out

  2. In the /etc/tomcat7/logging.properties, i updated the below property: 1catalina.org.apache.juli.FileHandler.directory = /xyz (this starting saving catalina.2016-03-19.log files to my custom location; instead of the catalina.out)

Neither of the above work for me. Please help. Thanks Jaskaran

3 Answers

I have the same problem with tomcat 8.5.*

I followed the advice from rod.poli.diniz and did the following: Created an environment variable in my ~/bash_profile

export CATALINA_LOGS_1=/home/user1/apps/logs/app1

In tomcat <tomcat-base>/bin/setenv.sh added the following JVM argument that is identified in <tomcat-base>/conf/logging.properties.

-Dcatalina.logs=$CATALINA_LOGS_1

Then updated <tomcat-base>/conf/logging.properties.

1catalina.org.apache.juli.AsyncFileHandler.level = FINE
1catalina.org.apache.juli.AsyncFileHandler.directory = ${catalina.logs}/catalina
1catalina.org.apache.juli.AsyncFileHandler.prefix = catalina.

2localhost.org.apache.juli.AsyncFileHandler.level = FINE
2localhost.org.apache.juli.AsyncFileHandler.directory = ${catalina.logs}/catalina
2localhost.org.apache.juli.AsyncFileHandler.prefix = localhost.

3manager.org.apache.juli.AsyncFileHandler.level = FINE
3manager.org.apache.juli.AsyncFileHandler.directory = ${catalina.logs}/catalina
3manager.org.apache.juli.AsyncFileHandler.prefix = manager.

4host-manager.org.apache.juli.AsyncFileHandler.level = FINE
4host-manager.org.apache.juli.AsyncFileHandler.directory = ${catalina.logs}/catalina
4host-manager.org.apache.juli.AsyncFileHandler.prefix = host-manager.

Result:

In <tomcat-base>/logs/:

catalina.out
localhost_access_log.2019-04-12.txt
tomcat.pid

In $CATALINA_LOGS_1:

catalina.2019-04-12.log
host-manager.2019-04-12.log
localhost.2019-04-12.log
manager.2019-04-12.log

Expected:

In <tomcat-base>/logs/:

tomcat.pid

In $CATALINA_LOGS_1:

catalina.out
localhost_access_log.2019-04-12.txt
catalina.2019-04-12.log
host-manager.2019-04-12.log
localhost.2019-04-12.log
manager.2019-04-12.log

Solution:

Update <tomcat-base>/bin/setenv.sh with the following:

mkdir -p $CATALINA_LOGS_1
CATALINA_OUT=$CATALINA_LOGS_1/catalina.out

Update <tomcat-base>/conf/server.xml find the AccessLogValve. Replace directory="logs": --> directory="${cfrm.logs}"

The default place for tomcat logging configuration is:

CATALINA_HOME/conf/logging.properties.

You need to edit this file if you want to change the logging location. For tomcat 7 you have like this inside the file:

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

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

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

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

4host-manager.org.apache.juli.FileHandler.level = FINE
4host-manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
4host-manager.org.apache.juli.FileHandler.prefix = host-manager.

You need to replace ${catalina.base}/logs to your desired new directory/path. That is for tomcat's core logging. For your web application you should do that inside your specific application's log4j or other logging framework.

You can change the logging file location by two ways:

Method 1.) For example to write log files in "D:/logs" path, edit /tomcat7/config/logging.properties as like shown below and restart the tomcat service.

1catalina.org.apache.juli.FileHandler.directory = D:/logs

2localhost.org.apache.juli.FileHandler.directory = D:/logs

3manager.org.apache.juli.FileHandler.directory = D:/logs

4host-manager.org.apache.juli.FileHandler.directory = D:/logs

Note: It only write log files like catalina, manager, host-manager, commons-deamon.

If you want to write stdout and stderr file also in the same path, follow second method.

Method 2). Go to /tomcat7/bin/ and open Tomcatw.exe with administrator rights -> Logging tab -> At Log path specify D:\logs. Apply settings and restart the tomcat service.

Note: Before applying the changes kindly check READ/WRITE permission given to appropriate user that the tomcat used (Log On) to run it's service.

Related