问题
I'm trying to use logback as the logging framework for my new project.
I placed the logback.xml in main\resources\logback.xml
.
These are the contents of logback.xml
file
<configuration debug="true">
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>D:/logbacklog.log</file>
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern>
</layout>
</appender>
<logger name="com.myproject" level="ALL"/>
<root level="debug">
<appender-ref ref="FILE" />
</root>
</configuration>
However, logs I enter do get printed in the console (may be it's using the default configuration).
I extracted my WAR file and found that it is in WEB-INF\classes
. I think it's the proper place. Any idea why my configuration file is not getting detected ?
PS : I tried making mistakes intentionally in my configuration file (like improper XML format), but still no error was thrown .
This is the Maven dependency for Logback.
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.13</version>
</dependency>
回答1:
JBoss AS helpfully diverts your logging to its own JBoss Log framework. See Logback and Jboss 7 - don't work together?
On my project, I gave up trying to use Logback (except in tests) and just put up with JBoss logging, because it was able to do everythin we needed.
回答2:
Just add following dependecy into your pom.xml file,
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.6</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.0.7</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.7</version>
</dependency>
来源:https://stackoverflow.com/questions/20242213/log-back-not-able-to-find-the-configuration-file-logback-xml