How to write logback StatusManager data to log file?

354 Views Asked by At

According to the logback website, we can write StatusManager data with StatusListener. There is mainly 2 status listener for writing status manager message.

  1. OnConsoleStatusListener - Print the message on the console, i.e. on System.out
  2. 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?

1

There are 1 best solutions below

0
On

Since logback does not provide a StatusListener implementation to send status messages to a file, you'll need to provide your own implementation of ch.qos.logback.core.status.StatusListener. For simplicity, extend ch.qos.logback.core.status.OnPrintStreamStatusListenerBase and override its getPrintStream() method to provide a PrintStream to a log file.

Then configure logback to use your status listener:

<statusListener class="yourpackage.YourStatusListener" /> 

Alternatively, you can use the logback-provided OnConsoleStatusListener and redirect your program output to a file.