berbt
berbt

Reputation: 262

Get file name of the newest log during runtime using logback

Is there a method to get the name of the current file (at runtime) without having to scan folders for the newest log created?

I'm currenty using logback 1.1.1

Upvotes: 1

Views: 197

Answers (1)

David Roussel
David Roussel

Reputation: 5916

I don't think so, as in general logback can be logging to many files at the same time. You could create your own appender that saved the file name in a singleton that your app could access.

To do this yourself extend ch.qos.logback.core.rolling.RollingFileAppender, override openFile(String file_name) and you can get the name of the logfile each time it changes. Remember to delegate to super.openFile(String file_name), otherwise the file won't actually be opened.

Then in logback.xml change your config to use your own appender.

Upvotes: 2

Related Questions