How to configure tomcat to rollover catalina.log files

后端 未结 2 554
一整个雨季
一整个雨季 2021-01-01 01:55

I\'m trying to configure my tomcat to rollover log files once a size limit is reached. I\'m running tomcat as a windows service and am redirecting all my stdout to catalina.

相关标签:
2条回答
  • 2021-01-01 02:18

    According to the Official Tomcat 7 documentation :


    public class FileHandler extends java.util.logging.Handler

    Implementation of Handler that appends log messages to a file named {prefix}{date}{suffix} in a configured directory.

    The following configuration properties are available:

    • directory - The directory where to create the log file. If the path is not absolute, it is relative to the current working directory of the application. The Apache Tomcat configuration files usually specify an absolute path for this property, ${catalina.base}/logs Default value: logs

    • rotatable - If true, the log file will be rotated on the first write past midnight and the filename will be {prefix}{date}{suffix}, where date is yyyy-MM-dd. If false, the file will not be rotated and the filename will be {prefix}{suffix}. Default value: true

    • prefix - The leading part of the log file name. Default value: juli.

    • suffix - The trailing part of the log file name. Default value: .log

    • bufferSize - Configures buffering. The value of 0 uses system default buffering (typically an 8K buffer will be used). A value of <0 forces a writer flush upon each log write. A value >0 uses a BufferedOutputStream with the defined value but note that the system default buffering will also be applied. Default value: -1

    • encoding - Character set used by the log file. Default value: empty string, which means to use the system default character set.

    • level - The level threshold for this Handler. See the java.util.logging.Level class for the possible levels. Default value: ALL

    • filter - The java.util.logging.Filter implementation class name for this Handler. Default value: unset

    • formatter - The java.util.logging.Formatter implementation class name for this Handler. Default value: java.util.logging.SimpleFormatter

    0 讨论(0)
  • 2021-01-01 02:36

    org.apache.juli.FileHandler does not support rotation based on file size and does not have the limit and count properties you are trying to set (see docs). Instead, you can use the standard Java java.util.logging.FileHandler which supports size-based rotation. You should change the following lines in your configuration:

    handlers = 1catalina.java.util.logging.FileHandler, 2localhost.org.apache.juli.FileHandler, 3manager.org.apache.juli.FileHandler, 4host-manager.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
    
    .handlers = 1catalina.java.util.logging.FileHandler, java.util.logging.ConsoleHandler
    

    Also note that Java FileHandler is configured slightly differently than Tomcat FileHandler

    1catalina.java.util.logging.FileHandler.level = FINEST
    1catalina.java.util.logging.FileHandler.pattern = <your log dir>/catalina%g.log
    1catalina.java.util.logging.FileHandler.limit = 100000
    1catalina.java.util.logging.FileHandler.count = 5
    1catalina.java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
    

    However, I'm not sure that redirecting standard out to the file written by the logger will work well and help you achieve what you want.

    0 讨论(0)
提交回复
热议问题