Output Liquibase log through TinyLog

63 views Asked by At

I want to use TinyLog to log Liquibase output. On the Liquibase website I found the information that they are now using JUL for logging: https://docs.liquibase.com/tools-integrations/extensions/extension-upgrade-guides/lb-4.0-upgrade-guide.html?Highlight=logger#How_logging_works

So it seems there is no need to implement an own logger based on the AbstractLogger anymore. Instead I tried to forwared the JUL logging to TinyLog. Therefore I followed the instruction on https://tinylog.org/v2/download-preview/#java-util-logging-jul Now instead of get the Logging of Liquibase I get a StachOverflowError.

I entered the code: org.tinylog.jul.JulTinylogBridge.activate(); to a ServletContextListener that is executed on startup. As soon as the first log method is called I get:

java.lang.StackOverflowError
    at org.tinylog.runtime.ModernJavaRuntime.getCallerStackTraceElement(ModernJavaRuntime.java:96)
    at org.tinylog.runtime.RuntimeProvider.getCallerStackTraceElement(RuntimeProvider.java:143)
    at org.tinylog.core.TinylogLoggingProvider.log(TinylogLoggingProvider.java:164)
    at org.tinylog.jul.BridgeHandler.publish(BridgeHandler.java:44)
    at java.logging/java.util.logging.Logger.log(Logger.java:979)
    at java.logging/java.util.logging.Logger.doLog(Logger.java:1006)
    at java.logging/java.util.logging.Logger.logp(Logger.java:1172)
    at org.apache.juli.logging.DirectJDKLog.log(DirectJDKLog.java:173)
    at org.apache.juli.logging.DirectJDKLog.debug(DirectJDKLog.java:96)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1254)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1220)
    at org.tinylog.runtime.ModernJavaRuntime.getCallerStackTraceElement(ModernJavaRuntime.java:96)
    at org.tinylog.runtime.RuntimeProvider.getCallerStackTraceElement(RuntimeProvider.java:143)
    at org.tinylog.core.TinylogLoggingProvider.log(TinylogLoggingProvider.java:164)
1

There are 1 answers

0
Martin On

Web servers like Tomcat have their own logging backend that cannot be easily disabled. Since Tomcat uses java.util.logging as its native logging backend, you can't redirect log entries to tinylog via the jul-tinylog bridge.

In general, when using web or application servers, it is recommended to use the tinylog-api together with a server adaptor instead of the native tinylog-impl backend. For Tomcat, tinylog-jul is the correct artifact. You don't need any bindings nor bridges for third-party logging APIs. So, you have to remove jul-tinylog from your classpath. Instead, you need to configure your logging through Tomcat instead of tinylog. However, you can still use the tinylog logging API, of course.

If you want to output log entries via Tomcat and tinylog-impl in parallel, you can do so by adding both tinylog-impl and tinylog-jul to your classpath. In this case, all log entries output via the tinylog logging API will be submitted to the Tomcat logging backend and the tinylog backend in parallel. Unfortunately, this only affects log entries that are output via the tinylog logging API, and you cannot output log entries from Liquibase via the tinylog backend.