How to clear a log file programatically?

I have two log files setup in a logback file.

<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
              <pattern>%d{MM/dd/yyyy HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%X{User} %msg%n</pattern>

  <appender name="datafile1" class="ch.qos.logback.core.FileAppender">

In java these are set up like so:

private static final Logger logger = LoggerFactory


private static final Logger logger = LoggerFactory

The first is the standard application log file. The second stores data which the program retreives from a db.

The program then compares data within the logfile and sends out some results. After this is completed, I would like to clear this log(datafile1) so it is empty and ready for the next run. How can I do this?

N.b the program is a 24hour process that uses a scheduler to run this job. It does not restart each time the job is run.


Seems that you're using the log file as a data store? Log files aren't designed for this, so there isn't actually a way to clear them. If you want to store data in a temporary location, open a file for writing, don't log it.

Need Your Help

ArgumentError in SongsController#create missing required :bucket option

ruby-on-rails ruby-on-rails-4

I've been trying to get paperclip working with amazon s3 all day and I'm gettin' pretty close.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.