Question

I have a logback configuration file like this: http://pastebin.com/yZGVWKEV

My problem is that what I'm logging out gets logged into the files, but what other libraries (e.g. spring, and logback) is logging out it doesn't.

They appear only on the console, but on that the format is not in my defined format:

15:07:25,226 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [.../logback-local-config.xml] at [file:.../logback-local-config.xml]
15:07:25,352 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
15:07:25,356 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [CONSOLE]
15:07:25,397 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
15:07:25,462 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
15:07:25,467 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [INFO_FILE]
15:07:25,495 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - Will use gz compression
15:07:25,498 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - Will use the pattern ./logs/%d{yyyy,aux}/%d{MM,aux}/service.%d{yyyyMMdd}.%d{HHmmssSSS,aux}-debug.log for the active file
15:07:25,504 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyyMMdd' from file name pattern './logs/%d{yyyy,aux}/%d{MM,aux}/service.%d{yyyyMMdd}.%d{HHmmssSSS,aux}-debug.log.gz'.
15:07:25,504 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight.
15:07:25,508 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to Sun Mar 23 15:05:59 CET 2014
15:07:25,510 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
15:07:25,514 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[INFO_FILE] - Active log file name: ./logs/service-debug.log
15:07:25,514 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[INFO_FILE] - File property is set to [./logs/service-debug.log]
15:07:25,516 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
15:07:25,516 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [DEBUG_FILE]
15:07:25,518 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - Will use gz compression
15:07:25,521 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - Will use the pattern ./logs/%d{yyyy,aux}/%d{MM,aux}/service.%d{yyyyMMdd}.%d{HHmmssSSS,aux}-info.log for the active file
15:07:25,522 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyyMMdd' from file name pattern './logs/%d{yyyy,aux}/%d{MM,aux}/service.%d{yyyyMMdd}.%d{HHmmssSSS,aux}-info.log.gz'.
15:07:25,522 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight.
15:07:25,522 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to Sun Mar 23 15:05:59 CET 2014
15:07:25,523 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
15:07:25,524 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[DEBUG_FILE] - Active log file name: ./logs/service-info.log
15:07:25,524 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[DEBUG_FILE] - File property is set to [./logs/service-info.log]
15:07:25,525 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.springframework.beans.factory.xml] to DEBUG
15:07:25,525 |-INFO in ch.qos.logback.classic.joran.action.LevelAction - ch.* level set to DEBUG
15:07:25,526 |-INFO in ch.qos.logback.classic.joran.action.LevelAction - com.* level set to DEBUG
15:07:25,526 |-INFO in ch.qos.logback.classic.joran.action.LevelAction - org.* level set to DEBUG
15:07:25,526 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to DEBUG
15:07:25,526 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [CONSOLE] to Logger[ROOT]
15:07:25,527 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [INFO_FILE] to Logger[ROOT]
15:07:25,527 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [DEBUG_FILE] to Logger[ROOT]
15:07:25,527 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
15:07:25,528 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@4adde028 - Registering current configuration as safe fallback point
márc. 23, 2014 3:07:25 DU org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [.../application.xml]
márc. 23, 2014 3:07:25 DU org.springframework.context.support.GenericApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.GenericApplicationContext@38987d26: startup date [Sun Mar 23 15:07:25 CET 2014]; root of context hierarchy
márc. 23, 2014 3:07:25 DU org.springframework.beans.factory.config.PropertyPlaceholderConfigurer loadProperties
INFO: Loading properties file from class path resource [.../service.properties]
2014-03-23 15:07:25.985 [main] INFO  ....Main$ - Service startup successful...

How can I achive that everything gets logged into the files as well, and in the correct format?

Was it helpful?

Solution

In order to configure spring logging to logback, You need to follow following steps.

  1. Exclude spring's logging framework that is spring uses commons-logging, exclude the commons-dependency jar.

     <exclusions>
        <!-- Exclude Commons Logging in favor of SLF4j -->
        <exclusion>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
        </exclusion>
    </exclusions>
    
  2. Now use slfj for spring using jcl.

     <dependency>
           <groupId>org.slf4j</groupId>
           <artifactId>jcl-over-slf4j</artifactId>
           <version>${slf4j.version}</version>
     </dependency>
    
  3. Now add the spring log level to logback.xml.

    <logger name="org.springframework">
        <level value="INFO" />
    </logger>
    
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top