There are many ways to cut Catalian logs, such as shell scripts, cronolog or configuration log4j, and so on. But today I'm going to introduce the use of logrotate to generate logs by date.
The original is a foreign blogger's article, here to share to you.
If the size of the catalina.out exceeds 2G, Tomcat may crash without error prompting and cannot start. So in order to avoid this problem, we should divide catalina.out every day.
How to cut catalina.out1 automatically when the catalina.out or size reaches 5M per day. Create a new file
Create a new file in the/etc/logrotate.d/directory, and name it arbitrarily.
1 /etc/logrotate.d/tomcat
2. Copy the following statement to the new file above
1 /var/log/tomcat/catalina.out { copytruncate daily rotate 7 compress Missingok Size 5M }
Specific meanings of each configuration:
- Make sure /var/log/tomcat/catalina.out points to the address of the catalina.out in your server
- Daily -cut daily
- rotate -up to seven files reserved
- Compress -compress the split file
- size -split when Catalina.out is greater than 5M
How it works
- Every night, cron daemon automatically performs tasks under the /etc/cron.daily directory.
- This will trigger the /etc/cron.daily/logrotate file, Logrotate is usually installed with Linux. It will execute this command-"/etc/sbin/logrotate/etc/logrotate.conf" (note space)
- /etc/logrotate.conf contains all the scripts in the /etc/logrotate.d directory
- This will trigger the previous step you wrote the /etc/logrotate.d/tomcate file
Perform logrotate manually
Execute the following statement to run the cron task manually
1 /usr/sbin/logrotate/etc/logrotate.conf
More operations for Logrotate
1 Mans logrotate
From http://www.vineetmanohar.com
Split Tomcat's Catalina logs using Logrotate