Tomcat 7- Change location of log files
Asked Answered
T

4

4

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

Takeoff answered 19/3, 2016 at 12:48 Comment(0)
C
4

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}"

Cheesy answered 12/4, 2019 at 11:28 Comment(0)
P
1

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.

Pleuropneumonia answered 5/7, 2018 at 0:5 Comment(0)
S
1

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.

Seedy answered 10/8, 2020 at 8:41 Comment(0)
M
0

You can follow below to change Tomcat Log Locations as you prefer:

This is for Linux: and should be mostly the same for Windows as well.

Locate the tomcat installed location: <tomcat-base>/conf/logging.properties

catalina.org.apache.juli.AsyncFileHandler.level = FINE
catalina.org.apache.juli.AsyncFileHandler.directory = <add_location_you_prefer>
catalina.org.apache.juli.AsyncFileHandler.prefix = catalina.

localhost.org.apache.juli.AsyncFileHandler.level = FINE
localhost.org.apache.juli.AsyncFileHandler.directory = <add_location_you_prefer>
localhost.org.apache.juli.AsyncFileHandler.prefix = localhost.

manager.org.apache.juli.AsyncFileHandler.level = FINE
manager.org.apache.juli.AsyncFileHandler.directory = <add_location_you_prefer>
manager.org.apache.juli.AsyncFileHandler.prefix = manager.

host-manager.org.apache.juli.AsyncFileHandler.level = FINE
host-manager.org.apache.juli.AsyncFileHandler.directory = <add_location_you_prefer>
host-manager.org.apache.juli.AsyncFileHandler.prefix = host-manager.

Finally you will need to change the catalina.out:

Locate the following code snippet in Catalina.sh script in bin directory of your tomcat base location:

if [ -z "$CATALINA_OUT" ] ; then
  CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out
fi

Change the

CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out

to:

CATALINA_OUT=<add_location_you_prefer>/catalina.out

Mechanist answered 6/5, 2023 at 5:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.