Logback - delete the log file on startup

java, logback

Solution

Include `<param name="Append" value="false" />` in your appender to clean the log file on start up.

Otherwise try this one

http://veerasundar.com/blog/2009/08/how-to-create-a-new-log-file-for-each-time-the-application-runs/

Problem

I want to delete the log file each time the program is started as opposed to it being appended. I've tried using the cleanHistoryOnStart property but that seems to have no effect whatsoever. I'm probably missing something here. I am on Linux and using Eclipse if that matters. ``` <?xml version="1.0" encoding="utf-8"?> <configuration scan="true" scanPeriod="10 seconds"> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>%d{dd.MM.yyyy. HH:mm:ss} %level [%thread] %logger{20} - %msg%n</pattern> </encoder> </appender> <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>chat.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>chat.log.%d{yyyy-MM-dd}</fileNamePattern> <cleanHistoryOnStart>true</cleanHistoryOnStart> </rollingPolicy> <encoder> <pattern>%d{dd.MM.yyyy. HH:mm:ss} %level [%thread] %logger{20} - %msg%n</pattern> </encoder> <Encoding>utf-8</Encoding> </appender> <logger name="src" additivity="false" level="ALL"> <appender-ref ref="STDOUT"/> <appender-ref ref="FILE"/> </logger> <root level="OFF"> <appender-ref ref="STDOUT"/> </root> </configuration> ```

Original source