17

我有几个使用 java.util.logging 的 webapps。Tomcat 5.5 被配置为使用 Juli 记录器,因此每个 webapp 都有自己的日志文件。问题是 Juli 没有最大文件大小和文件数的属性。使用 Juli,文件将无限增长,并且只会在一天结束时滚动。此外,保留无限数量的日志文件。

您可以在此页面上看到 FileHandler 属性 - Apache Tomcat 5.5 文档
没有限制或计数属性(以下几行什么都不做)
org.apache.juli.FileHandler.limit=102400
org.apache.juli.FileHandler.count=5

在不更改 webapps 的情况下,有没有办法为每个应用程序获取唯一的日志文件,并在日志文件大小上有某种类型的界限?

更新: 我找到的解决方案根本不使用 Juli 记录器! java.util.logging.FileHandler.limit=102400
java.util.logging.FileHandler.count=5

谢谢,

格雷格

4

2 回答 2

3

Update: I see your point now after reading more. "Tomcat's JULI implementation is not intended to be a fully-featured logging libary, only a simple bridge to those libraries. However, JULI does provide several properties for configuring the its handlers. These are listed below." Funny that they say that the default java.util.Logging implementation is too limited then they work around it by providing an even more limiting implementation.

FileHandler javadocs

  • java.util.logging.FileHandler.limit specifies an approximate maximum amount to write (in bytes) to any one file. If this is zero, then there is no limit. (Defaults to no limit).
  • java.util.logging.FileHandler.count specifies how many output files to cycle through (defaults to 1).

for the one file per web app, you probably want to separate it by the name of the logger and it depends on how the loggers are created for each app. If they're based off the package or class name then you can filter the logs based on that. It looks like the sample on the link you provided tells how to do this

org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = \
   2localhost.org.apache.juli.FileHandler
于 2008-09-25T21:37:37.743 回答
3

编辑:刚刚意识到您想要每个 webapp 日志记录,这可能无法通过此设置...

假设您使用的是 Tomcat 6.0,我的建议是编译额外的组件以实现完整的公共日志记录并使用 Log4j 配置滚动日志。

此处的构建说明 http://tomcat.apache.org/tomcat-6.0-doc/building.html

然后替换Tomcat的/bin目录下的tomcat-juli.jar,将tomcat-juli-adapters.jar连同log4j.jar和log4j.properties一起放到/lib目录下。

然后使用类似的东西:

<appender name="file" class="org.apache.log4j.RollingFileAppender">
  <param name="File" value="logfile.log"/>
  <param name="Threshold" value="INFO"/>
  <param name="MaxFileSize" value="10MB"/>
  <param name="MaxBackupIndex" value="3"/>
  <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern" value="%d{ISO8601} %p %m%n"/>
  </layout>
</appender>
于 2008-10-05T14:51:51.320 回答