SoFunction
Updated on 2025-04-06

How to configure tomcat to save 7-day scrolling logs

In Tomcat,Files are used to configure Java logging framework ()of. To achieveThe log is saved for 7 days, and the log file name every day has a timestamp. You can configure it according to the following steps:

1. Back up the original configuration

ModificationBefore the file, back it up to prevent configuration errors from causing problems. This file is usually located in$CATALINA_BASE/confIn the directory.

2. Modify the configuration

The following is a specific configuration example, which can enable the function of scrolling by day and retaining 7 days:

properties

# Configure the root logger, specify the log level and the processor usedhandlers = , , , 
# Configure the console log processor and can be adjusted as needed.handlers = 
# Configure catalina log processor = FINE
 = ${}/logs
# Add date format to filename = catalina.
 =.log
 = 7
# Turn on scrolling by day = true
 = 
# Other log processor configurations remain unchanged, such as localhost, manager, and host-manager = FINE
 = ${}/logs
 = localhost.
 =.log
 = 7
 = true
 = 
 = FINE
 = ${}/logs
 = manager.
 =.log
 = 7
 = true
 = 
 = FINE
 = ${}/logs
 = host-manager.
 =.log
 = 7
 = true
 = 
# Configure logging level of logger.[Catalina].[localhost].level = INFO
.[Catalina].[localhost].handlers = 
.[Catalina].[localhost].[/manager].level = INFO
.[Catalina].[localhost].[/manager].handlers = 
.[Catalina].[localhost].[/host-manager].level = INFO
.[Catalina].[localhost].[/host-manager].handlers = 

3. Configuration instructions

  • : This is used for processingcatalinaAsynchronous file processor for logs.
    • level: Specify the log level asFINE, can be adjusted according to needs.
    • directory: Specify the storage directory of the log file, which is used here$CATALINA_BASE/logs
    • prefixandsuffixprefixprefixed as the log file name,suffixAs the suffix, the log file name will becatalina.date.logThe form, the date is automatically added by Tomcat.
    • maxDays: Set the number of days of retention of log files to 7 days, and log files that exceed 7 days will be automatically deleted.
    • rotatable: Set totrueIt means that the function of scrolling logs by day is enabled.
    • formatter: The formatter for the specified log is

4. Restart Tomcat

Completely modifiedAfter the file, you need to restart Tomcat to make the configuration take effect. After restarting, Tomcat will generate a new log file every day as configured, with the file name with a date, and will automatically delete the log file 7 days ago.

Through the above steps, you can achieveThe logs scroll by day and retain the function of 7 days.

This is the article about how to configure tomcat to save 7-day scrolling logs. For more related to tomcat to save 7-day scrolling logs, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!