Is there a Logback appender that redirects to JUL (java.util.logging)?
I have a problem similar to this question. My applications are running on a Java application server (WebSphere) and use Logback, because I want to write log messages to a separate log file as an addition to the application server's default log file. This allows configuring different log levels for administrators and developers. Admins look at the app server log and developers at their separate log file.
WebSphere internally uses JUL. So, the common solution seems to be ConsoleAppender. At first this seems to solve the issue. But unfortunately the log level gets lost and instead of a meaningful log level codes (E, W, I, ...) you always get O, as pointed out in the linked SO question above. This is because ConsoleAppender just writes to System.out and System.err.
Everything I can find about such a JUL appender is either out dated or is about the jul-to-slf4j-bridge. The bridge is not a solution for me. As its name says it redirects JUL messages to slf4j where we have the opposite requirement - redirecting slf4j to JUL. Although you probably could solve the problem with the bridge, it'll cause other issues in an app server environment, where JUL is managed by the core.
As there seems to be no solution, we made our own. IIRC it's based on this Log4j solution.
The great thing about it is that we can even enable tracing in the WebSphere console. That means you can use Logback methods
isDebugEnabled()orisTraceEnabled()to check whether JUL trace level is enabled in WebSphere.The appender:
Convert Logback to JUL log level:
Logback turbo filter for
isDebugEnabled()etc. supportExample configuration. Our goal with this configuration was to write INFO messages in a separate log file instead of "spamming" WebSphere's SystemOut.log. Warnings and errors should appear in SystemOut.log. If trace is enabled the messages should be written to WebSphere's trace.log: