Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

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>

I simply added the following line:

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
415 views
Welcome To Ask or Share your Answers For Others

1 Answer

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...