1

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.

1 Answers1

0

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")

Martin
  • 598
  • 1
  • 4
  • 27
  • I only use the writer in append mode, and as far as I can see, it never overwrites an existing log file. I'll design a dedicated test that writes enough log messages to trigger the size policy and see what happens. – Vittorio Torroni Jan 16 '18 at 20:44
  • Append mode is only available for FileWriter and SharedFileWriter but not for RollingFileWriter: http://www.tinylog.org/configuration#writers – Martin Jan 16 '18 at 22:52
  • I may have misunderstood how the configuration works. – Vittorio Torroni Jan 18 '18 at 08:47
  • I have configured my logger as follows:`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();` – Vittorio Torroni Jan 18 '18 at 08:56
  • Every time I re-start the application (within the same day), the logger keeps appending messages to the same log file. – Vittorio Torroni Jan 18 '18 at 08:57
  • Yes, you are right that the log file will be continued after re-starting the application (a StartupPolicy has to be defined to start a new log file after each re-start). But the log file will be not continued when the SizePolicy triggers a new log file. – Martin Jan 18 '18 at 09:25
  • If a policy triggers a new file name that is equal to the previous one, the log file will be overwritten. Therefore, I recommend defining a more precise date and time pattern for TimestampLabeler. An alternative would to remove the SizePolicy if you don't want to start a new log file. – Martin Jan 18 '18 at 09:42
  • Thanks Martin, now I understand. For the time being, I'd like to keep the SizePolicy, because I don't know if the log file can grow too big, so I'll modify my TimeStampLabeler as you suggested. In the future, if I see that the log file, under all scenarios, will never grow too big, I'll remove the SizePolicy and revert to the original format of the TimeStampLabeler. – Vittorio Torroni Jan 18 '18 at 10:48