[logback-user] Redirecting JDK 9's JVM logs to Logback?

Osvaldo Doederlein opinali at gmail.com
Mon Dec 4 16:02:28 CET 2017


Hi,

I want to redirect the JVM's internal logs to Logback, is this possible?
More specifically, I have all my app logs going to a single appender and I
want JVM logs such as GC to be writing to the same appender, interleaved
with app logs.

I have Logback configured with slf4j and jul-to-slf4j, also I wrote a
System.LoggerFinder service to redirect System.Logger to SLF4J->Logback,
which I can see working for core lib logs such as java.base /
sun.net.www.protocol.http.HttpURLConnection.  (See
http://openjdk.java.net/jeps/158) However, the GC logs are still going to
stdout. The documentation for JEP 158 seems to imply that the JVM logs are
something separate from java.util.logging, can only be sent to stderr,
stdout or a log file, but not to a JUL logger.

I know that I can hook the System.out/err streams and redirect writes to a
logger, but this is not ideal, for one thing I cannot configure Logback to
send logs back to stdout (which I often do in test/interactive runs)
without risking a stack overflow.  I could write code that walks the stack
to decide if the call to System.err/out is coming from a logger, but this
is expensive.

Anyone knows a magic trick here? :-)



-- 
Osvaldo Doederlein |  https://twitter.com/opinali |
https://plus.google.com/+OsvaldoDoederlein
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20171204/8c6aff62/attachment.html>


More information about the logback-user mailing list