slf4j和logback:不附加运行时错误

时间:2014-01-16 22:08:09

标签: java android logging slf4j logback

我将错误日志附加到文件中。但是,如果我的应用程序崩溃并且存在未捕获的运行时异常,则该文件没有该错误日志以及堆栈跟踪。

我的配置文件是:

<property name="LOG_DIR" value="/sdcard/ApplicationName" />
<appender name="logcat" class="ch.qos.logback.classic.android.LogcatAppender">
    <encoder>
        <pattern>%msg</pattern>
    </encoder>
</appender>

<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
        <level>ERROR</level>
    </filter>
    <file>${LOG_DIR}/ApplicationName.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
        <fileNamePattern>${LOG_DIR}/ApplicationName.%i.log</fileNamePattern>
        <minIndex>1</minIndex>
        <maxIndex>10</maxIndex>
    </rollingPolicy>

    <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
        <maxFileSize>1MB</maxFileSize>
    </triggeringPolicy>

    <encoder>
        <pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n%rEx{full}</pattern>
    </encoder>
</appender>

<!-- Write TRACE (and higher-level) messages to the log file -->
<root level="TRACE">
    <appender-ref ref="logcat" />
    <appender-ref ref="FILE" />
</root>

0 个答案:

没有答案