This example shows how to use SLF4J with Java Util Logging (JUL) as a logging implementation.
<dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-jdk14</artifactId> <version>1.8.0-alpha2</version> </dependency>
handlers= java.util.logging.ConsoleHandler .level= INFO java.util.logging.ConsoleHandler.level = INFO java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter java.util.logging.SimpleFormatter.format=[%1$tF %1$tT] [%4$s] %5$s %n
package com.logicbig.example; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class MyClass { private static Logger LOGGER = LoggerFactory.getLogger(MyClass.class); public static void doSomething() { LOGGER.info("a test message"); } }
package com.logicbig.example; public class ExampleMain { public static void main(String[] args) { String path = ExampleMain.class.getClassLoader() .getResource("jul-log.properties") .getFile(); System.setProperty("java.util.logging.config.file", path); MyClass.doSomething(); } }
[2017-08-03 16:14:39] [INFO] a test message
Dependencies and Technologies Used: