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

查看:103
本文介绍了如何让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的反馈,我的appender看起来像这样:

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.

推荐答案

如果将追加参数设置为 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天全站免登陆