【问题标题】:Logback log everything into fileLogback 将所有内容记录到文件中
【发布时间】:2014-04-30 19:00:34
【问题描述】:

我有一个这样的 logback 配置文件:http://pastebin.com/yZGVWKEV

我的问题是我正在注销的内容会登录到文件中,但其他库(例如 spring 和 logback)正在注销它没有。

它们只出现在控制台上,但格式不是我定义的格式:

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...

我怎样才能使所有内容都以正确的格式登录到文件中?

【问题讨论】:

    标签: java configuration logback


    【解决方案1】:

    为了将spring logging配置为logback,您需要按照以下步骤操作。

    1. 排除spring的日志框架,即spring使用commons-logging,排除commons-dependency jar。

       <exclusions>
          <!-- Exclude Commons Logging in favor of SLF4j -->
          <exclusion>
              <groupId>commons-logging</groupId>
              <artifactId>commons-logging</artifactId>
          </exclusion>
      </exclusions>
      
    2. 现在使用 jcl 将 slfj 用于 spring。

       <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>jcl-over-slf4j</artifactId>
             <version>${slf4j.version}</version>
       </dependency>
      
    3. 现在将 spring 日志级别添加到 logback.xml。

      <logger name="org.springframework">
          <level value="INFO" />
      </logger>
      

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-13
      • 1970-01-01
      • 2013-12-07
      • 2013-11-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多