slf4j + java.util.logging: how to configure?

Basically, you just need to have slf4j-api.1.7.7.jar and slf4j-jdk14.1.7.7.jar on your classpath. And then create a logging.properties file for your application and set System properties -Djava.util.logging.config.file={path_to_logging.properties}

check this tutorial out which gives you examples how to configure slf4j with different logging frameworks such as java logger, log4j, logback etc.


There is no configuration in the slf4j layer. It is just an API, which the backend must provide the implementation for (more or less).

To use java.util.logging as the slf4j backend, you must have slf4j-jdk14-mumle.jar from the slf4j distribution on your classpath, and do the magic listed in the javadoc to enable it. If not you will have a runtime error saying there is no slf4j implementation active.


I've dropped Java logging on the same purpose and went for logback. There is nothing to do to configure logback with SLF4J actually. Just put logback.xml to the root of the jar with logback configuration and put logback-XX.jar on classpath.

<configuration>

  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <!-- encoders are assigned the type
         ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
    <encoder>
      <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
    </encoder>
  </appender>

  <root level="warn">
    <appender-ref ref="STDOUT" />
  </root>
</configuration>

This is a config for logging to console, but logback manual has more examples.


See this tutorial on jul:

java -Djava.util.logging.config.file=myLoggingConfigFilePath

But I would recommend to go for Logback