我正在尝试配置我的 tomcat,以便在达到大小限制后滚动日志文件。我将 tomcat 作为 Windows 服务运行,并将所有 stdout 重定向到 catalina.log。这是我通过 logs.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 似乎不起作用
答案1
您正在使用 FileHandler,记录如下:http://tomcat.apache.org/tomcat-6.0-doc/api/org/apache/juli/FileHandler.html 它没有“限制”属性,只会随着日期变化而旋转。
您可以配置 tomcat 以使用更灵活的 log4j,请参阅此页面:http://tomcat.apache.org/tomcat-6.0-doc/logging.html#Using_Log4j
不建议在上下文中使用 swallowOutput(上面页面就是这么说的)