有这个pom的项目:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.5.RELEASE</version>
</dependency>
</dependencies>
</project>
src/test/java/foobar/Test.java
中的此测试:
package foobar;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class Test {
private static final Log LOG = LogFactory.getLog(Test.class);
public void testMe() {
LOG.info("Hello World");
}
}
和src/test/resources/logging.properties
:
handlers= java.util.logging.ConsoleHandler
.level=ALL
java.util.logging.ConsoleHandler.level = ALL
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format=Hello %1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %4$s %2$s %5$s%6$s%n
然后,拨打
mvn clean install -Djava.util.logging.config.file=src/test/resources/logging.properties
打印
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running foobar.Test
Hello 2017-10-06 16:30:19 INFO foobar.Test testMe Hello World
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.013 sec
我看到 Hello 和 Hello World 。
如果我将依赖项更改为
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-webmvc</artifactId>
<version>2.6.6.RELEASE</version>
</dependency>
忽略logging.properties
- 文件。输出变为
-------------------------------------------------------
T E S T S
-------------------------------------------------------
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Running foobar.Test
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec
如何命令slf4j使用JUL?
答案 0 :(得分:0)
啊,我需要一个额外的依赖。
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.7.5</version>
</dependency>