0

I'm using the Tinylog library with the "rolling file" function to write logs to a file. Sometimes I need to clear a file.

Tried to do it with normal Java methods but it breaks the file and makes it hard to read. Is there a way to clear the log file at any point so it doesn't break?

Gorbachew
  • 5
  • 1

1 Answers1

0

You can use standard policies for starting new log files at defined events. This is the recommended way.

If you need more flexibility, you can use the DynamicPolicy for starting a new log file programmatically. This policy is part of tinylog 2.5. The first milestone is expected to be released during this month and will include this new policy.

Configuration:

writer          = rolling file
writer.file     = foo.log
writer.policies = dynamic

Start new log file in Java:

DynamicPolicy.setReset();
Martin
  • 598
  • 1
  • 4
  • 27
  • Hello again! Android development. Switched to version **2.5.0-M**. Started using DynamicNamePolicy. But ran into a problem: `W/System.err: LOGGER ERROR: Failed creating service implementation 'org.tinylog.writers.RollingFileWriter' (java.lang.IllegalArgumentException: Invalid token 'tinylog.directory' in '#{tinylog.directory}/log_{date:yyyy -MM-dd_HH-mm-ss}.txt')` At the same time, version **2.4.1** works correctly. I checked on the Android presentation application and updated the version there. Same error. Can you suggest what can be done? – Gorbachew Mar 05 '22 at 09:59
  • Could you provide your full tinylog configuration? By the way, the `DynamicNamePolicy` was renamed into `DynamicPolicy ` and `dynamic name` into `dynamic` respectively. – Martin Mar 05 '22 at 20:15
  • Here is the complete config file: [config](https://github.com/Gorbachew/presentations/blob/master/tinylog.properties) I also tried to upgrade the version on this [example project](https://github.com/tinylog-org/tinylog-android-example) and got the same error – Gorbachew Mar 07 '22 at 12:21
  • I could finally reproduce the issue and fix it in tinylog 2.5.0-M1.1 (see https://tinylog.org/v2/2022/03/update-for-first-milestone/). – Martin Mar 07 '22 at 21:14
  • Thanks for the fast support! Everything worked, now it's very convenient – Gorbachew Mar 09 '22 at 07:46