0
votes

I have an appender FILE, and want to direct org.springframwork and ch.qos.logback to this log file. However, when i run my application on linux server, the INFO message for these two packages does not go into the log file, but directly printed out. Here is my logback.xml:

<configuration debug="true">
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator"/>
<jmxConfigurator/>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>log/myfile.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
        <fileNamePattern>log/myfile.%i.log.gz</fileNamePattern>
        <minIndex>1</minIndex>
        <maxIndex>10</maxIndex>
    </rollingPolicy>
    <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
        <maxFileSize>500MB</maxFileSize>
    </triggeringPolicy>
    <encoder>
        <pattern>%d{ISO8601} %-5p [%t] [%c{1}] - %m%n</pattern>
    </encoder>
</appender>
<root level="${log.level:-INFO}">
    <appender-ref ref="FILE"/>
</root>
<logger name="org.springframework" level="INFO">
    <appender-ref ref="FILE"/>
</logger>
<logger name="ch.qos.logback" level="INFO">
    <appender-ref ref="FILE"/>
</logger>

08:23:22,446 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@1b83cfe9 - Registering current configuration as safe fallback point

Apr 09, 2015 8:23:22 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO: Loading XML bean definitions from class path resource [spring/spring-common.xml]

Can someone help point out what is wrong with my configuration? Thank you.

BTW: I read from logback documentation that I don't need to set same appender-ref for logger, otherwise it will be printed out into same appender twice. But i see from the logback debug info that only if i set appender-ref for logger, it will set appender for the logger.

1

1 Answers

0
votes

The first log output by ch.qos.logback can't be redirected using the log configuration because this output happens while Logback reads it's configuration -> hen / egg style problem.

To get rid of those messages, use debug="false" in your XML.

org.springframework doesn't use Logback unless you install a bridge for org.apache.commons.logging (which is the logging framework used by Spring). Look for jcl-over-slf4j.jar in the documentation at http://www.slf4j.org/legacy.html