【问题标题】:Logback-Android : "no applicable action" error when using FixedWindowRollingPolicy with a SizeBasedTriggeringPolicyLogback-Android:将 FixedWindowRollingPolicy 与 SizeBasedTriggeringPolicy 一起使用时出现“无适用操作”错误
【发布时间】:2013-01-30 04:09:17
【问题描述】:

每当启用日志记录(应用程序中的配置)时,我在我的 android 应用程序中使用logback-android 将消息记录到文件中。 它似乎工作正常,但是当我遇到以下情况时

  • 当日志大小达到 50MB 时轮换日志
  • 在日志轮换发生时创建备份文件。例如。 testFile.1.log.zip

为此,我有以下 logback.xml 文件:

<configuration>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
    <file>/sdcard/dappLog.log</file>
    <append>true</append>
    <encoder>
        <pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
    </encoder>
    <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
        <fileNamePattern>/sdcard/dappLog.%i.log.zip</fileNamePattern>
        <minIndex>1</minIndex>
        <maxIndex>2</maxIndex>
    </rollingPolicy>

    <triggeringPolicy class="com.dapp.utilities.SizeBasedTriggeringPolicy">
        <maxFileSize>50MB</maxFileSize>
    </triggeringPolicy>
</appender>

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

根据 this 的回答,因为 SizeBasedTriggerPolicy 中有一个 bug(src),所以我有以下实现:
`

package com.dapp.utilities;  
import java.io.File;  
import ch.qos.logback.core.util.FileSize;  
public class SizeBasedTriggeringPolicy<E> extends ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy<E> {  
    @Override  
    public boolean isTriggeringEvent(final File activeFile, final E event) {  
        return (activeFile.length() >= FileSize.valueOf(getMaxFileSize()).getSize());  
    }  
}

`

但是,当我运行它时,我收到以下错误:

I/System.out( 2346): 16:14:20,750 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@8:85 - no applicable action for [rollingPolicy], current pattern is [[configuration][appender][rollingPolicy]]  
I/System.out( 2346): 16:14:20,757 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@9:30 - no applicable action for [fileNamePattern], current pattern is [[configuration][appender][rollingPolicy][fileNamePattern]]  
I/System.out( 2346): 16:14:20,763 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@10:23 - no applicable action for [minIndex], current pattern is [[configuration][appender][rollingPolicy][minIndex]]  
I/System.out( 2346): 16:14:20,770 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@11:23 - no applicable action for [maxIndex], current pattern is [[configuration][appender][rollingPolicy][maxIndex]]  
I/System.out( 2346): 16:14:20,777 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@14:90 - no applicable action for [triggeringPolicy], current pattern is [[configuration][appender][triggeringPolicy]]  
I/System.out( 2346): 16:14:20,820 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@15:26 - no applicable action for [maxFileSize], current pattern is [[configuration][appender][triggeringPolicy][maxFileSize]]  

PS : 我是 logback 的新手。

【问题讨论】:

    标签: android logging logback


    【解决方案1】:

    &lt;AppenderRef ...&gt; 而不是&lt;appender-ref ...&gt; 的拼写错误也会导致此错误。

    【讨论】:

      【解决方案2】:

      自己解决了这个问题。这是因为appender 标签中的class 属性错误。
      所以下面的代码有效:

      <configuration>
      <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
          <file>/sdcard/dapp.log</file>
          <append>false</append>
      
          <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
              <fileNamePattern>/sdcard/dapp.%i.log.zip</fileNamePattern>
              <minIndex>1</minIndex>
              <maxIndex>2</maxIndex>
          </rollingPolicy>
      
          <triggeringPolicy class="com.bigbasket.dapp.utilities.SizeBasedTriggeringPolicy">
              <maxFileSize>50MB</maxFileSize>
          </triggeringPolicy>
          <encoder>
              <pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
          </encoder>
      </appender>
      
      <root level="INFO">
          <appender-ref ref="FILE"/>
      </root>
      

      【讨论】:

        猜你喜欢
        • 2016-07-10
        • 2019-02-15
        • 2017-07-08
        • 1970-01-01
        • 2021-06-25
        • 2018-06-16
        • 1970-01-01
        • 2017-12-16
        • 2015-09-03
        相关资源
        最近更新 更多