Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logback-Android : "no applicable action" error when using FixedWindowRollingPolicy with a SizeBasedTriggeringPolicy

I'm using logback-android in my android application to log messages to a file, whenever logging is enabled (configuration in app). It seems to be working fine, but when I have the following scenario

  • Rotate log when its size reaches 50MB
  • Create backup files for when the log rotation takes place. eg. testFile.1.log.zip

I have the following logback.xml file for this purpose:

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

As per this answer as there is a bug(src) in SizeBasedTriggerPolicy, so I have the following implementation:
`

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());  
    }  
}

`

However, when I'm running this, I'm getting the following error:

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 : I'm new to logback.

like image 210
Siddharth Srivastava Avatar asked Feb 14 '13 11:02

Siddharth Srivastava


2 Answers

Figured out the issue myself. It was because of the wrong class attribute in appender tag.
So the following code works:

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

like image 143
Siddharth Srivastava Avatar answered Nov 27 '22 18:11

Siddharth Srivastava


Having incorrect spelling of <AppenderRef ...> instead of <appender-ref ...> can cause this error too.

like image 43
Kyle Krull Avatar answered Nov 27 '22 18:11

Kyle Krull