如何在jboss 6 AS中旋转日志文件

时间:2014-01-08 10:03:25

标签: logging jboss6.x log-rotation

在我的jboss 6.1.0 final AS中我想保留30天的日志..

在jboss-logging.xml中有size-rotating-file-handler,我不想要.. 我需要每天旋转日志文件.. 如何更改日志配置

我的日志配置是 -

<periodic-rotating-file-handler
     file-name="${jboss.server.log.dir}/server.log"
     name="FILE"
     autoflush="true"
     append="true"
     suffix="..yyyy-MM-dd">  <!-- To roll over at the top of each hour, use ".yyyy-MM-dd-HH" instead -->

  <error-manager>
     <only-once/>
  </error-manager>

  <formatter>
     <!-- To revert back to simple stack traces without JAR versions, change "%E" to "%e" below. -->
     <!-- Uncomment this to get the class name in the log as well as the category
     <pattern-formatter pattern="%d %-5p [%c] %C{1} (%t) %s%E%n"/>
     -->
     <!-- Uncomment this to log without the class name in the log -->
     <pattern-formatter pattern="%d %-5p [%c] (%t) %s%E%n"/>
  </formatter>

请帮帮我

2 个答案:

答案 0 :(得分:2)

要每天使用一个文件保留30天的日志,请尝试以下操作...

<periodic-rotating-file-handler
     file-name="${jboss.server.log.dir}/server.log"
     name="FILE"
     autoflush="true"
     append="true"
     suffix=".dd">  <!-- To roll over at the top of each hour, use ".yyyy-MM-dd-HH" instead -->

  <error-manager>
     <only-once/>
  </error-manager>

  <formatter>
     <!-- To revert back to simple stack traces without JAR versions, change "%E" to "%e" below. -->
     <!-- Uncomment this to get the class name in the log as well as the category
     <pattern-formatter pattern="%d %-5p [%c] %C{1} (%t) %s%E%n"/>
     -->
     <!-- Uncomment this to log without the class name in the log -->
     <pattern-formatter pattern="%d %-5p [%c] (%t) %s%e%n"/>
  </formatter>
</periodic-rotating-file-handler>

答案 1 :(得分:0)

要了解后缀参数,您必须查看PeriodicRotatingFileHandler.java的来源并想知道。

setSuffix迭代后缀的字符,为每个字符创建一个Period对象,最后一个被占用。因此,如果后缀以m结尾,则采用Period.MINUTE。