Rolling File appender usage

∥☆過路亽.° 提交于 2019-12-11 04:55:06

问题


What is a rollingfile appender ?

I want my jboss to delete logs either exceeding a maximum size or exceeding a certain date. People on this forum have suggested me to use rollingfile appender.

How do I configure it in jboss-log4j.xml file ?


回答1:


Here is an example:

<!-- A time/date based rolling appender -->
<appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
  <param name="File" value="server.log"/>
  <param name="Append" value="false"/>

  <!-- Rollover at midnight each day -->
  <param name="DatePattern" value="'.'yyyy-MM-dd"/>

  <layout class="org.apache.log4j.PatternLayout">
    <!-- The default pattern: Date Priority [Category] Message\n -->
    <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
  </layout>
</appender>

Btw this is taken from our server's jboss-log4j.xml file - if you check your default server installation, I am fairly sure you find a similar configuration there ;-) Moreover, I guess if you add

  <param name="MaxFileSize" value="100KB"/>

to the above, you get it roll over upon reaching the specified size.

For more info on appenders, see the Log4J manual.



来源:https://stackoverflow.com/questions/2559804/rolling-file-appender-usage

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!