Split Tomcat's Catalina logs using Logrotate

Source: Internet
Author: User

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
    1. Every night, cron daemon automatically performs tasks under the /etc/cron.daily directory.
    2. 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)
    3. /etc/logrotate.conf contains all the scripts in the /etc/logrotate.d directory
    4. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.