本文介绍了如何配置tomcat来转换catalina.log文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.log. This is how I configured by logging.properties to set a size limit. But it is not working.

logging.properties

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似乎不起作用

But 1catalina.org.apache.juli.FileHandler.limit = 100000 doesn't seem to be working

推荐答案

org.apache.juli.FileHandler不支持基于文件大小的旋转,并且不具有您要设置的limitcount属性(参阅文档).相反,您可以使用支持基于大小的旋转的标准Java java.util.logging.FileHandler.您应该在配置中更改以下几行:

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

还请注意,Java FileHandler的配置与Tomcat FileHandler

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.

这篇关于如何配置tomcat来转换catalina.log文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-10 08:16