vfrolov Frolov
vfrolov Frolov

Reputation: 1

How to close rolling file?

I'm using the tinylog in version 2.7.0. This is my tinylog.properties file:

writer          = rolling file
writer.tag      = -
writer.level    = info
writer.format   = {{date:yyyy-MM-dd HH:mm:ss.SSS} [{level}]:|min-size=32} {message}
writer.file     = {dynamic}/System.out.log
writer.policies = dynamic
writer.charset  = UTF-8
writer.append   = true
writer.buffered = false

My application receives folders with tasks. Each task executes and leaves the result and task execution log (System.out.log) in the same folder. The process is endless. Folders with tasks are created asynchronously. If there are no tasks, then the application waits. The pseudocode for executing one task looks like this:

public void doJob(String pathOFJob) {
  DynamicSegment.setText(pathOFJob);
  
  // do job in path
}

This works, but there is one problem. The System.out.log file in the last job folder is not closed until the next job starts running (which may not be there for quite some time). Is it possible to close System.out.log after each job is completed?

I've tried to use ProviderRegistry.getLoggingProvider().shutdown(), but w/o success.

Upvotes: 0

Views: 32

Answers (1)

Martin
Martin

Reputation: 716

tinylog doesn't support such behavior out-of-the-box as it is a very specific use case that would break when running multiple jobs in parallel. However, you could implement a custom file writer that do exactly what you want.

You can find the documentation how to implement a custom writer here: https://tinylog.org/v2/extending/#custom-writer

A good starting point is tinylog's own file writer which consist of only a couple of code lines: https://github.com/tinylog-org/tinylog/blob/v2.8/tinylog-impl/src/main/java/org/tinylog/writers/FileWriter.java

Upvotes: 0

Related Questions