开发者

How do I get SLF4J to output some logging statements?

I'm using SLF4J for the first time in my Maven project, but I can't get it to output anything (its creators evidently don't subscribe to the "useful default behavior" philosophy).

I added the following to my pom.xml:

<dependency>
    <groupI开发者_如何转开发d>com.googlecode.sli4j</groupId>
    <artifactId>sli4j-slf4j-simple</artifactId>
    <version>2.0</version>
    <type>jar</type>
    <scope>compile</scope>
</dependency>

And I'm using it like this:

final Logger logger = LoggerFactory.getLogger(UdpRemoteConnection.class);

      ...

logger.error("test error");

Right now I don't need anything fancy, I just need it to log to the console. How do I enable this?


My usual config for Java projects with Maven:

pom.xml:

...
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.6.1</version>
</dependency>
<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>0.9.26</version>
</dependency>
...

src/main/resources/logback.xml or/and src/test/resources/logback.xml:

<configuration>
  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <layout class="ch.qos.logback.classic.PatternLayout">
      <Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern>
    </layout>
  </appender>

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

Logback is a implementation of slf4j and the successor of log4j.


It seems that you are using Sli4j instead of Slf4j.
Try to use Slf4j directly:

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>${slf4j.version}</version>
</dependency>


<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-simple</artifactId>
    <version>${slf4j.version}</version>
</dependency>

(I use 1.5.11 as slg4j.version, but latest available is 1.6.1)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜