0

In my classes I utilize loggers like the following:

private static org.slf4j.Logger logger = LoggerFactory.getLogger(SpecParser.class);

Now I would like to switch off certain loggers, ideally in a configuration file. For example above logger should not log debug messages. Is this possible? Below my try, that did not work. It is still printing all messages to stdout:

logback.xml:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

 <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
        <Pattern>%d{yyyy-MM-dd_HH:mm:ss.SSS} %-5level %logger{36} - %msg%n
                </Pattern>
    </encoder>
 </appender>

 <appender name="FILE"
    class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>c:/mkyongapp.log</file>
    <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
       <Pattern>%d{yyyy-MM-dd_HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
           </Pattern>
    </encoder>

    <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
        <FileNamePattern>log.%i.log.zip</FileNamePattern>
        <MinIndex>1</MinIndex>
        <MaxIndex>10</MaxIndex>
    </rollingPolicy>

    <triggeringPolicy
        class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
        <MaxFileSize>2MB</MaxFileSize>
    </triggeringPolicy>

  </appender>


  <logger name="de.tki.hbci.specification.SpecParser" level="WARN" />

  <root level="INFO">
    <appender-ref ref="FILE" />
    <appender-ref ref="STDOUT" />
  </root>

</configuration>
tobi
  • 753
  • 1
  • 14
  • 25

1 Answers1

0

Please check for other log files on the classpath that might have been read in before this logback.xml file. Depending on the usage, something earlier in the classpath might preempt this file, either in a plain text file or inside a JAR.

John Kelty
  • 107
  • 8
  • I don't think there is another configuration file. Would there be a way to find out? – tobi Apr 18 '16 at 18:07
  • There are a few suggestions listed on http://stackoverflow.com/questions/18922730/how-can-i-determine-what-log-configuration-source-logback-actually-used that might be helpful. You might also double check that SpecParser's package is correctly specified in your logback.xml file. Otherwise, it might be taking the INFO level from your root default. – John Kelty Apr 18 '16 at 19:45
  • Thanks a lot. With the information of above link I found out, that my application didnt find the lockback.xml, because it resided on the wrong place. – tobi Apr 19 '16 at 07:21