【问题标题】:logback config not archiving on size constraintlogback 配置未归档大小限制
【发布时间】:2021-12-30 11:47:54
【问题描述】:

我正在尝试将附加程序添加到我的 Spring Boot 应用程序中。

我在 logback.xml 文件中添加了以下配置:

<appender name="application.log"
              class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${APP_LOG_ROOT}/application.log</file>
        <encoder>
            <pattern>${LOG_PATTERN}</pattern>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
            <fileNamePattern>${APP_LOG_ROOT}/archivedLogs/info/application-%d-%i.log
            </fileNamePattern>
            <minIndex>1</minIndex>
            <maxIndex>10</maxIndex>
        </rollingPolicy>
        <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            <maxFileSize>100MB</maxFileSize>
        </triggeringPolicy>
    </appender>

但文件在达到 100 mb 时仍未存档 我在 java args 中添加了日志记录配置; -Dlogging.config=/etc/DemoService/logback.xml

如果我遗漏了什么,请告诉我

谢谢。

【问题讨论】:

    标签: spring-boot logging


    【解决方案1】:

    你是通过你的&lt;root&gt;&lt;/root&gt;引用这个appender吗?:

    例子:

    <configuration scan="true">
    
       <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    
        <File>${org.eclipse.m2e.log.dir}/0.log</File>
    
        <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
          <FileNamePattern>${org.eclipse.m2e.log.dir}/%i.log</FileNamePattern>
          <MinIndex>1</MinIndex>
          <MaxIndex>10</MaxIndex>
        </rollingPolicy>
    
        <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
          <MaxFileSize>100MB</MaxFileSize>
        </triggeringPolicy>
    
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
          <pattern>%date [%thread] %-5level %logger{35} - %msg%n</pattern>
        </encoder>
    
      </appender>
    
            
      <root level="INFO">
        <appender-ref ref="FILE" />
      </root>
    
    </configuration>
    

    【讨论】:

    • 不,我没用过这样的东西
    猜你喜欢
    • 1970-01-01
    • 2018-03-26
    • 1970-01-01
    • 2011-09-15
    • 2018-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多