如何让 log4j 在启动时清除日志? [英] How do I make log4j clear a log at startup?

查看:17
本文介绍了如何让 log4j 在启动时清除日志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望日志在应用程序运行时一直滚动,但我希望在应用程序重新启动时日志重新开始.

I want the log to roll over as long as the application is running, but I want the log to start fresh when the application is restarted.

更新:根据 erickson 的反馈,我的附加程序看起来像这样:

Updated: Based on erickson's feedback, my appender looks like this:

   <appender name="myRFA" class="org.apache.log4j.RollingFileAppender">
      <param name="File" value="my-server.log"/>
      <param name="Append" value="false" />
      <param name="MaxFileSize" value="10MB"/>
      <param name="MaxBackupIndex" value="10"/>
      <layout class="org.apache.log4j.PatternLayout">
         <param name="ConversionPattern"
            value="%d{ISO8601} %p - %t - %c - %m%n"/>
      </layout>
   </appender>

我只是添加了以下行:

<param name="Append" value="false" />

现在它会在启动时截断基本日志文件,但不会影响滚动文件.

It now truncates the base log file at startup, but it leaves the rolled files alone.

推荐答案

如果将 append 参数设置为 false,基础日志文件将重新启动"当应用程序重新启动时.您的意思是您也希望删除任何滚动"日志文件吗?

If you set the append parameter to false, the base log file will be "started fresh" when the application restarts. Do you mean that you want any "rolled" log files to be deleted too?

这篇关于如何让 log4j 在启动时清除日志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆