如何为tomcat设置最大卷数和最大日志大小? [英] How to set maximum number of rolls and maximum log size for tomcat?
问题描述
我有空间问题所以需要限制catalina.out的大小到10M并限制滚动次数到前3天。
是否可以只配置logging.properties?
谢谢。
I have problem with space so need limit size of catalina.out to 10M and limit number of rolls to 3 previous days. Is it possible with only configure logging.properties? Thanks.
推荐答案
由于Tomcat内部使用JUL进行记录,您可以使用系统属性 java.util.logging.config.file
指定属性文件的文件路径。对于此属性文件的格式,您可以引用 JRE_HOME / lib / logging.properties
(这是JUL使用的默认配置文件)
As Tomcat internally uses JUL to log , you can use the system property java.util.logging.config.file
to specify the file path of the properties file. For the format of this properties file , you can refer to your JRE_HOME/lib/logging.properties
(which is the default configuration file used by JUL)
但是, JUL不支持每日轮换。如果您不介意,可以使用其 java.util.logging.FileHandler
来根据日志的文件大小旋转日志文件:
However, JUL does not support the daily rotation . If you don't mind , you can use its java.util.logging.FileHandler
to rotate the log files based on the log 's file size instead:
# Define the FileHandler
handlers= java.util.logging.FileHandler
# Configure the FileHandler
java.util.logging.FileHandler.pattern = %h/java%u.log
java.util.logging.FileHandler.limit = 1024000
java.util.logging.FileHandler.count = 3
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.FileHandler.append=true
然后,每个日志文件的限制大小为1024000字节(1MB),最大滚动到3个输出日志文件。您可以参考 java.util.logging的Javadoc .FileHandler 了解有关配置的详细信息。
Then , each log file will has the limit size 1024000 bytes (1MB) , and maximum roll to 3 output log files . You can refer the Javadoc of java.util.logging.FileHandler for the details about the configuration.
如果要使用JUL支持每日轮换,则必须实现文件处理程序。我从此博客中找到了自定义实现。我还没试过。如果您有兴趣,可以参考。
You have to implemnt the File Handler if you want to support rotation on daily basis using JUL . I found a custom implemenation from this blog . I did not try it yet. You can refer it if you have any interest.
这篇关于如何为tomcat设置最大卷数和最大日志大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!