Search code examples
javatinylog

Tinylog: Using DailyPolicy and SizePolicy together on a RollingFileWriter


If a RollingFileWriter is configured with both a DailyPolicy and a SizePolicy, and the size of a daily log exceeds the size configured in the SizePolicy, presumably Tinylog what will close the current log file and open a new one, but what name will give them? I have configured the Daily Policy with TimestampLabeler("yyyy-MM-dd") which gives a unique filename for each day, but if the size policy is triggered, a second file would presumably need to be created. In that case, what name will it have? This is how I have configured my logger:

 Configurator.defaultConfig()
                .writer(new RollingFileWriter(LOG_DIR + "/CryoSip.log", 90, new TimestampLabeler("yyyy-MM-dd"), new DailyPolicy(), new SizePolicy(1000 * 1024)))
                .formatPattern("{date:yyyy-MM-dd HH:mm:ss} {level}: {message}")
                .activate();    

Every time I re-start my application, the logger keeps appending messages to the same log file, even though the RollingFileWriter does not support append mode. I'm not sure I understand what is the expected behaviour of TinyLog with this configuration.


Solution

  • Each time the RollingFileWriter starts a new log file, it evaluates the configured labeler exactly as it has been configured and overwrites any existing log file. Therefore the date time pattern for TimestampLabeler should be more precise and include the time, if you use both a DailyPolicy and a SizePolicy. For example: TimestampLabeler("yyyy-MM-dd_HH-mm-ss")