Home Operation and Maintenance Linux Operation and Maintenance How to configure Tomcat log rotation

How to configure Tomcat log rotation

Apr 13, 2025 am 08:06 AM
linux tool tomcat ai

How to configure Tomcat log rotation

This article introduces how to use the logrotate tool provided by Linux system to achieve automatic rotation of Tomcat logs.

Step 1: Create or modify the logrotate configuration file

In the /etc/logrotate.d/ directory, create or modify a configuration file named tomcat (or other name you choose). Use the following command:

 sudo vim /etc/logrotate.d/tomcat
Copy after login

Step 2: Add or modify the configuration file content

Tomcat's catalina.out log file rotation in the configuration file:

 <code>/usr/local/tomcat/logs/catalina.out { daily rotate 7 compress missingok notifempty copytruncate }</code>
Copy after login

Parameter description:

  • daily : Rotate once a day.
  • rotate 7 : Keep the last 7 log files.
  • compress : The log file after rotation is compressed ( .gz format).
  • missingok : If the log file does not exist, the error is ignored.
  • notifempty : Rotate only when the log file is not empty.
  • copytruncate : Copy the current log file and then truncate the original file instead of directly deleting the original file.

Step 3: Test the configuration file

Before applying configuration, test whether the configuration file syntax is correct:

 logrotate -d /etc/logrotate.d/tomcat
Copy after login

If there is no error, the output displays "no errors".

Step 4: Reload the logrotate configuration

Use the following command to make the configuration take effect:

 sudo logrotate -f /etc/logrotate.d/tomcat
Copy after login

Or, restart the logrotate service:

 sudo systemctl restart logrotate
Copy after login

Step 5: Verify the configuration

Check the /usr/local/tomcat/logs/catalina.out file and its backup file to confirm whether the log rotation works as expected.

Rotation of other log files

For other Tomcat log files, you can create separate configuration files, or use scripts to manage log rotations for multiple applications. Please adjust the path in the configuration file according to the actual Tomcat installation path. This example assumes that Tomcat is installed in the /usr/local/tomcat directory.

The above is the detailed content of How to configure Tomcat log rotation. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Top 10 digital currency exchanges Top 10 digital currency app exchanges Top 10 digital currency exchanges Top 10 digital currency app exchanges Apr 22, 2025 pm 03:15 PM

The top ten digital currency exchanges are: 1. OKX, 2. Binance, 3. gate.io, 4. Coinbase, 5. Kraken, 6. Huobi, 7. KuCoin, 8. Bitfinex, 9. Bitstamp, 10. Poloniex. These exchanges are selected based on factors such as transaction volume, user experience and security, and all provide a variety of digital currency trading services and an efficient trading experience.

Linux Operations: Managing Files, Directories, and Permissions Linux Operations: Managing Files, Directories, and Permissions Apr 23, 2025 am 12:19 AM

In Linux, file and directory management uses ls, cd, mkdir, rm, cp, mv commands, and permission management uses chmod, chown, and chgrp commands. 1. File and directory management commands such as ls-l list detailed information, mkdir-p recursively create directories. 2. Permission management commands such as chmod755file set file permissions, chownuserfile changes file owner, and chgrpgroupfile changes file group. These commands are based on file system structure and user and group systems, and operate and control through system calls and metadata.

Free viewing market software websites What are the top ten free viewing market software websites Free viewing market software websites What are the top ten free viewing market software websites Apr 24, 2025 pm 02:21 PM

Top 10 free-to-view market software websites are recommended: 1. Binance, 2. OkX, 3. Sesame Open Door (KuCoin), 4. CoinMarketCap, 5. CoinGecko, 6. TradingView, 7. Investing.com, 8. Yahoo Finance, 9. Glassnode Studio, 10. LunarCrush, these websites provide real-time data, technical analysis tools and market information to help you make informed investment decisions.

Binance download link Binance download path Binance download link Binance download path Apr 24, 2025 pm 02:12 PM

To safely download the Binance APP, you need to go through the official channels: 1. Visit the Binance official website, 2. Find and click the APP download portal, 3. Choose to scan the QR code, app store, or directly download the APK file to download to ensure that the link and developer information are authentic, and enable two-factor verification to protect the security of the account.

How does hardware compatibility differ between Linux and Windows? How does hardware compatibility differ between Linux and Windows? Apr 23, 2025 am 12:15 AM

Linux and Windows differ in hardware compatibility: Windows has extensive driver support, and Linux depends on the community and vendors. To solve Linux compatibility problems, you can manually compile drivers, such as cloning RTL8188EU driver repository, compiling and installing; Windows users need to manage drivers to optimize performance.

2025 Most Complete Exchange Ranking 2025 Virtual Currency Exchange Ranking 2025 Most Complete Exchange Ranking 2025 Virtual Currency Exchange Ranking Apr 24, 2025 pm 01:48 PM

The top ten mainstream virtual currency exchanges in the world in 2025 are: 1. Binance, 2. Ouyi, 3. Bybit, 4. Coinbase, 5. Sesame Open, 6. Bitget, 7. Kraken, 8. MEXC, 9. KuCoin, 10. Bitfinex. These exchanges have outstanding performance in terms of trading volume, user experience, security, compliance and market influence, and are suitable for investors with different needs.

macOS vs. Linux: Exploring the Differences and Similarities macOS vs. Linux: Exploring the Differences and Similarities Apr 25, 2025 am 12:03 AM

macOSandLinuxbothofferuniquestrengths:macOSprovidesauser-friendlyexperiencewithexcellenthardwareintegration,whileLinuxexcelsinflexibilityandcommunitysupport.macOS,developedbyApple,isknownforitssleekinterfaceandecosystemintegration,whereasLinux,beingo

Bian download tutorial Bian latest version download tutorial Bian download tutorial Bian latest version download tutorial Apr 24, 2025 pm 12:36 PM

The steps to download the latest version of Bian are as follows: 1. Visit the official website of Bian. 2. Select the appropriate version (Windows, macOS, Linux). 3. Download the installation package. 4. Double-click the installation package and follow the prompts to install. 5. Enter the activation code and configure the settings. 6. Regularly update and scan the system to ensure safety.

See all articles