1

I'm using slf4j and log4j2 combination as logging framework in my application. To redirect logs of java.util.logging into slf4j, I'm using jul-to-slf4j. I also have to execute :

static {
        LogManager.getLogManager().reset();
        SLF4JBridgeHandler.install();
    }

the above to register the handler to make this work and it is working fine. But I would like to avoid this static block if it possible to do the same handler register by using log4j2.xml file configuration. I spent much time to find the xml configuration but could not found it.

Progman
  • 16,827
  • 6
  • 33
  • 48
akr
  • 123
  • 1
  • 1
  • 9

1 Answers1

0

If you are not running the code in a servlet container like Tomcat you can simply add the -Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager to the launch command.

Otherwise should be able to use a logging.properties file with contents:

handlers=org.slf4j.bridge.SLF4JBridgeHandler
org.apache.logging.log4j.jul.Log4jBridgeHandler.propagateLevels = true

Then launch the application with -Djava.util.logging.config.file=logging.properties. You'll have to adjust the path to the logging.properties

jmehrens
  • 10,580
  • 1
  • 38
  • 47