Clearing Tomcat logs on startup

Standard

Tomcat logs can become overwhelming to read in a development environment. Usually, you would only need to see the most recent error logs when testing your program. The older errors are irrelevant. This simple shell script solves the problem of error logs piling up.

Navigate to the tomcat/bin folder. Edit the file named “startup.sh”. You will need to be logged in as root to perform these changes. Place the following code at the top of the file, directly after the last comments.

# -----------------------------------------------------------------------------
# Start Script for the CATALINA Server
# -----------------------------------------------------------------------------

echo "DELETING OLD LOG FILES ..."
cd ../logs
rm catalina*
rm local*
rm manager*
rm admin*
rm host*

echo "DELETING OLD WEB APP ..."
cd ../webapps
rm -r YOURAPPNAME

echo "PERFORMING NORMAL STARTUP ..."
cd ../bin

Now when Tomcat starts it will remove all old log files, and the application folder before proceeding.

Using with Netbeans

To deploy with Netbeans navigate to Services -> Servers -> Apache Tomcat (Your server). Right click and select Properties. There will be a tab labeled Startup. Select Use Custom Catalina Script. Finally, browse and select the tomcat startup.sh script that was edited above.

netbean-catalina-script-custom

2 thoughts on “Clearing Tomcat logs on startup

Leave a Reply

Your email address will not be published.