According to the logback website, we can write StatusManager
data with StatusListener
.
There is mainly 2 status listener for writing status manager message.
- OnConsoleStatusListener - Print the message on the console, i.e. on System.out
- OnErrorConsoleStatusListener - Print the message on the console, i.e. on System.error
But I need to write those StatusManager
messages to the error log. Is there any way to do this?
Since logback does not provide a
StatusListener
implementation to send status messages to a file, you'll need to provide your own implementation ofch.qos.logback.core.status.StatusListener
. For simplicity, extendch.qos.logback.core.status.OnPrintStreamStatusListenerBase
and override itsgetPrintStream()
method to provide aPrintStream
to a log file.Then configure logback to use your status listener:
Alternatively, you can use the logback-provided
OnConsoleStatusListener
and redirect your program output to a file.