Logback-Android:将FixedWindowRollingPolicy与SizeBasedTriggeringPolicy一起使用时出现“无适用操作”错误

我在我的 Android应用程序中使用 logback-android将消息记录到文件,只要启用了日志记录(在app中配置).
它似乎工作正常,但当我有以下情况

>当大小达到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.

解决方法

我自己想出了这个问题.这是因为appender标签中的类属性错误.
以下代码有效:
<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>

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...