I am stumped with logback for a week already. My File's appender seems to log less than my Console's appender. My console's appender showed exception error when my Jetty goes up (due to myclass calls something into Jetty) yet those exception is not being shown in my File's appender. I have tried many different combination and still yield no change to my File's appender. Do I miss something big in logback ? please help.

<appender name="FILE"
    class="ch.qos.logback.core.rolling.RollingFileAppender">
    <encoder>
        <pattern>%d{HH:mm:ss z} [%thread] %-5level %logger{16}:%line- %msg%n%xException</pattern>
    </encoder>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <!-- daily rollover period -->
        <fileNamePattern>${LOG_DIR}/MARI-%d.log</fileNamePattern>
        <!-- keep 7 days' worth of history -->
        <maxHistory>14</maxHistory>
    </rollingPolicy>
</appender>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
        <pattern>%d{HH:mm:ss z} [%thread] %-5level %logger{16}:%line- %msg%n%xException</pattern>
    </encoder>
</appender>

<logger name="com.myclass" level="TRACE" additivity="false">
    <appender-ref ref="STDOUT"/> 
    <appender-ref ref="FILE"/>      
</logger>

<root level="ERROR"> 
    <appender-ref ref="STDOUT"/> 
    <appender-ref ref="FILE"/> 
</root> 

有帮助吗?

解决方案

Found out from other stackoverflow's issue that I must surround the piece of code with try-catch and catch the generic Exception to get all the thrown exception.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top