View Javadoc
1   package com.github.valfirst.slf4jtest;
2   
3   import java.util.logging.Level;
4   import java.util.logging.LogManager;
5   import org.slf4j.bridge.SLF4JBridgeHandler;
6   
7   /**
8    * Configuration to redirect log messages from {@link java.util.logging} to SLF4J.
9    *
10   * @author Karsten Spang
11   */
12  public class JulConfig {
13  
14      /**
15       * Redirect all logging from {@link java.util.logging} to SLF4J. If called more than once, it will
16       * do nothing on subsequent calls.
17       */
18      public static void setup() {
19          if (!SLF4JBridgeHandler.isInstalled()) {
20              synchronized (JulConfig.class) {
21                  if (!SLF4JBridgeHandler.isInstalled()) {
22                      SLF4JBridgeHandler.removeHandlersForRootLogger();
23                      SLF4JBridgeHandler.install();
24                      LogManager.getLogManager().getLogger("").setLevel(Level.ALL);
25                  }
26              }
27          }
28      }
29  
30      private JulConfig() {}
31  }