Log back not able to find the configuration file (logback.xml)

会有一股神秘感。 提交于 2019-12-08 02:04:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!