logbackslf4jmaven-jetty-pluginjul-to-slf4j

Force Jetty Maven Plugin to use SLF4J instead of JUL for Jetty's logs?


Using Maven 3:

jetty maven plugin - version 11.0.24, logback classic - version 1.4.14, jul-to-slf4j version 2.0.16 :

public class MyLifecycleListener implements ServletContextListener {
  @Override
  public void contextInitialized(ServletContextEvent sce) {
   LogManager.getLogManager().reset();
   SLF4JBridgeHandler.install();
   ...

Logback works ok for application logs but jetty logs are still formatted as JUL: as evidenced by level WARNING instead of WARN. Formatting in logback.xml is ignored.

There is no such problem using Logback with embedded Jetty started in main().

system property org.eclipse.jetty.util.log.class is set as org.eclipse.jetty.util.log.Slf4jLog in Maven

In both cases after SLF4JBridgeHandler.install():

SLF4J LoggerFactory.getILoggerFactory().getClass() returns: class ch.qos.logback.classic.LoggerContext

The only java.util.logging.Logger Handler found is: org.slf4j.bridge.SLF4JBridgeHandler

someone here Configure logging for Jetty's maven plugin? said Plugins don't see the project dependencies. You need to specify inside the .You need to specify a concrete slf4j implementation, such as logback-classic inside jetty-maven-plugin, so I've done that.


Solution

  • The solution was to upgrade to v12 & enable the logging-jul-capture module, which I could only get to work in EXTERNAL mode.

    I then noticed an anomaly of the plugin: when logback-classic is declared in the plugin the transitive dependency logback-core is not resolved, so that has to be explicitly declared. If logback-classic is declared only in the main dependencies the transitive dependency is resolved.

    The question now is how to remove the default Jetty SLF4J binding & force jetty's internal logs to use logback instead of the default Jetty SLF4J provider ?