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
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>
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
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
Or, restart the logrotate service:
sudo systemctl restart logrotate
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

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.

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.

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.

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.

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.

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.

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

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.
