Tôi đang sử dụng logback-android trong ứng dụng Android của mình để ghi nhật ký vào tệp, bất cứ khi nào ghi nhật ký được bật (cấu hình trong ứng dụng). Nó dường như được làm việc tốt, nhưng khi tôi có các tình huống sauLogback-Android: lỗi "không áp dụng hành động" khi sử dụng FixedWindowRollingPolicy với một SizeBasedTriggeringPolicy
- Xoay đăng nhập khi kích thước của nó đạt 50MB
- Tạo file sao lưu cho khi xoay log diễn ra. ví dụ. testFile.1.log.zip
Tôi có sau logback.xml tập tin cho mục đích này:
<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>
Theo this câu trả lời là có một bug (src) trong SizeBasedTriggerPolicy, vì vậy tôi có triển khai sau:
`
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());
}
}
'
Tuy nhiên, khi tôi đang chạy này, tôi nhận được lỗi sau:
I/System.out(2346): 16:14:20,750 |-ERROR in [email protected]:85 - no applicable action for [rollingPolicy], current pattern is [[configuration][appender][rollingPolicy]]
I/System.out(2346): 16:14:20,757 |-ERROR in [email protected]:30 - no applicable action for [fileNamePattern], current pattern is [[configuration][appender][rollingPolicy][fileNamePattern]]
I/System.out(2346): 16:14:20,763 |-ERROR in [email protected]:23 - no applicable action for [minIndex], current pattern is [[configuration][appender][rollingPolicy][minIndex]]
I/System.out(2346): 16:14:20,770 |-ERROR in [email protected]:23 - no applicable action for [maxIndex], current pattern is [[configuration][appender][rollingPolicy][maxIndex]]
I/System.out(2346): 16:14:20,777 |-ERROR in [email protected]:90 - no applicable action for [triggeringPolicy], current pattern is [[configuration][appender][triggeringPolicy]]
I/System.out(2346): 16:14:20,820 |-ERROR in [email protected]:26 - no applicable action for [maxFileSize], current pattern is [[configuration][appender][triggeringPolicy][maxFileSize]]
PS: Tôi mới đến Logback.