Move Tomcat Logs File Location: Tips

I need to move Tomcat’s default logs folder (/opt/tomcat/apache-tomcat-9.0.26/logs) to a new location (e.g. /usr/log). Below is the view structure of the logs folder:

-rw-r----- 1 root root 0 Dec 26 06:01 manager.2019-12-26.log
-rw-r----- 1 root root 0 Dec 26 06:01 host-manager.2019-12-26.log
-rw-r----- 1 root root 0 Dec 26 06:01 localhost_access_log.2019-12-26.txt
-rw-r----- 1 root root 2481 Dec 26 06:12 localhost.2019-12-26.log
-rw-r----- 1 root root 31443 Dec 26 06:12 catalina.2019-12-26.log
-rw-r----- 1 root root 1042803 Dec 26 06:24 catalina.out

To move Tomcat’s default logs folder to a new location, follow these steps:

  1. Stop Tomcat service using the command sudo systemctl stop tomcat
  2. Copy the entire logs folder to the new location using the command sudo cp -r /opt/tomcat/apache-tomcat-9.0.26/logs /usr/log/
  3. Edit Tomcat’s catalina.sh file using the command sudo nano /opt/tomcat/bin/catalina.sh
  4. Find the line CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out and replace it with CATALINA_OUT="/usr/log/catalina.out"
  5. Find the line CATALINA_OPTS="$CATALINA_OPTS -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties" and add this at the end -Dcatalina.base=/opt/tomcat -Dcatalina.home=/opt/tomcat -Dcatalina.logs=/usr/log
  6. Save the file and exit the editor
  7. Start Tomcat service using the command sudo systemctl start tomcat