gpt4 book ai didi

tomcat - 如何配置tomcat以翻转catalina.log文件

转载 作者:行者123 更新时间:2023-11-28 21:47:38 25 4
gpt4 key购买 nike

我正在尝试将我的 tomcat 配置为在达到大小限制后翻转日志文件。我将 tomcat 作为 Windows 服务运行,并将我所有的标准输出重定向到 catalina.log。这就是我通过 logging.properties 配置大小限制的方式。但它不起作用。

日志记录属性

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

.handlers = 1catalina.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler

############################################################
# Handler specific properties.
# Describes specific configuration info for Handlers.
############################################################

1catalina.org.apache.juli.FileHandler.level = FINE
1catalina.org.apache.juli.FileHandler.directory = e:/apache-tomcat/logs/server_111-1001
1catalina.org.apache.juli.FileHandler.prefix = catalina.
1catalina.org.apache.juli.FileHandler.limit = 100000 # size 100kb
1catalina.org.apache.juli.FileHandler.count = 5


2localhost.org.apache.juli.FileHandler.level = FINE
2localhost.org.apache.juli.FileHandler.directory = e:/apache-tomcat/logs/server_111-1001
2localhost.org.apache.juli.FileHandler.prefix = localhost.

3manager.org.apache.juli.FileHandler.level = FINE
3manager.org.apache.juli.FileHandler.directory = e:/apache-tomcat/logs/server_111-1001
3manager.org.apache.juli.FileHandler.prefix = manager.

4host-manager.org.apache.juli.FileHandler.level = FINE
4host-manager.org.apache.juli.FileHandler.directory = e:/apache-tomcat/logs/server_111-1001
4host-manager.org.apache.juli.FileHandler.prefix = host-manager.

java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter


############################################################
# Facility specific properties.
# Provides extra control for each logger.
############################################################

org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = 2localhost.org.apache.juli.FileHandler

org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].handlers = 3manager.org.apache.juli.FileHandler

org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].handlers = 4host-manager.org.apache.juli.FileHandler

# For example, set the com.xyz.foo logger to only log SEVERE
# messages:
#org.apache.catalina.startup.ContextConfig.level = FINE
#org.apache.catalina.startup.HostConfig.level = FINE
#org.apache.catalina.session.ManagerBase.level = FINE
#org.apache.catalina.core.AprLifecycleListener.level=FINE

但是 1catalina.org.apache.juli.FileHandler.limit = 100000 似乎不起作用

最佳答案

org.apache.juli.FileHandler 不支持基于文件大小的旋转,并且没有 limitcount 属性试图设置(see docs)。相反,您可以使用支持基于大小的轮换的标准 Java java.util.logging.FileHandler。您应该在配置中更改以下行:

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

另请注意,Java FileHandler 的配置与 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

但是,我不确定将标准输出重定向到记录器写入的文件是否会很好地工作并帮助您实现您想要的。

关于tomcat - 如何配置tomcat以翻转catalina.log文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9220189/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com