Logback 缺少 RollingFileAppender 和 AysncAppender 的条目
Logback missing entries for RollingFileAppender and AysncAppender
您好,我使用的是 logback 版本 1.1.10,我的配置如下:
我在记录事件时遇到了一个大问题,找不到所需的日志。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="abc_req" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${log}/abc/request/request.log</File>
<encoder>
<pattern>%m%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log}/abc/request/request.log.%d{yyyy-MM-dd-HH}</fileNamePattern>
</rollingPolicy>
</appender>
<appender name="abc1_res" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${log}/abc1/response/response.log</File>
<encoder>
<pattern>%m%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log}/abc1/response/response.log.%d{yyyy-MM-dd-HH}</fileNamePattern>
</rollingPolicy>
</appender>
<appender name="abc2_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${log}/abc2/error/error.log</File>
<encoder>
<pattern>%m%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log}/abc2/error/error.log.%d{yyyy-MM-dd-HH}</fileNamePattern>
</rollingPolicy>
</appender>
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<Target>System.out</Target>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p:: %m%n</pattern>
</encoder>
</appender>
<logger name="abcLogRequest" level="INFO" additivity="false">
<appender-ref ref="abc_req"/>
</logger>
<logger name="abc1LogResponse" level="INFO" additivity="false">
<appender-ref ref="abc1_res"/>
</logger>
<logger name="abc2LogError" level="ERROR" additivity="false">
<appender-ref ref="abc2_error"/>
</logger>
<appender name="requestQueue" class="ch.qos.logback.classic.AsyncAppender">
<discardingThreshold>0</discardingThreshold>
<queueSize>1000</queueSize>
<appender-ref ref="abc_req"/>
</appender>
<appender name="responseQueue" class="ch.qos.logback.classic.AsyncAppender">
<discardingThreshold>0</discardingThreshold>
<queueSize>1000</queueSize>
<appender-ref ref="abc1_res"/>
</appender>
<appender name="errorQueue" class="ch.qos.logback.classic.AsyncAppender">
<discardingThreshold>0</discardingThreshold>
<queueSize>500</queueSize>
<appender-ref ref="abc2_error"/>
</appender>
<!--
<shutdownHook class="ch.qos.logback.core.hook.DelayingShutdownHook"/> -->
<root level="INFO">
<appender-ref ref="stdout"/>
</root>
</configuration>
但是在签入滚动文件时,文件中丢失了很多日志条目。
在上述情况下确实需要帮助。
任何help/suggestion真的可以帮到我很多!
终于解决了!
问题:有 2 个 JVM 试图写入一个公共文件。
所以只需在 RollingFileAppender 中添加以下内容
<prudent>true</prudent>
并在配置中删除文件参数。
<appender name="abc_req" class="ch.qos.logback.core.rolling.RollingFileAppender">
<prudent>true</prudent>
<encoder>
<pattern>%m%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log}/abc/request/request.log.%d{yyyy-MM-dd-HH}</fileNamePattern>
</rollingPolicy>
</appender>
另外,通过 rollingPolicy 中的 fileNamePattern,我能够提供正确的文件路径。
您好,我使用的是 logback 版本 1.1.10,我的配置如下: 我在记录事件时遇到了一个大问题,找不到所需的日志。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="abc_req" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${log}/abc/request/request.log</File>
<encoder>
<pattern>%m%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log}/abc/request/request.log.%d{yyyy-MM-dd-HH}</fileNamePattern>
</rollingPolicy>
</appender>
<appender name="abc1_res" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${log}/abc1/response/response.log</File>
<encoder>
<pattern>%m%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log}/abc1/response/response.log.%d{yyyy-MM-dd-HH}</fileNamePattern>
</rollingPolicy>
</appender>
<appender name="abc2_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${log}/abc2/error/error.log</File>
<encoder>
<pattern>%m%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log}/abc2/error/error.log.%d{yyyy-MM-dd-HH}</fileNamePattern>
</rollingPolicy>
</appender>
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<Target>System.out</Target>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p:: %m%n</pattern>
</encoder>
</appender>
<logger name="abcLogRequest" level="INFO" additivity="false">
<appender-ref ref="abc_req"/>
</logger>
<logger name="abc1LogResponse" level="INFO" additivity="false">
<appender-ref ref="abc1_res"/>
</logger>
<logger name="abc2LogError" level="ERROR" additivity="false">
<appender-ref ref="abc2_error"/>
</logger>
<appender name="requestQueue" class="ch.qos.logback.classic.AsyncAppender">
<discardingThreshold>0</discardingThreshold>
<queueSize>1000</queueSize>
<appender-ref ref="abc_req"/>
</appender>
<appender name="responseQueue" class="ch.qos.logback.classic.AsyncAppender">
<discardingThreshold>0</discardingThreshold>
<queueSize>1000</queueSize>
<appender-ref ref="abc1_res"/>
</appender>
<appender name="errorQueue" class="ch.qos.logback.classic.AsyncAppender">
<discardingThreshold>0</discardingThreshold>
<queueSize>500</queueSize>
<appender-ref ref="abc2_error"/>
</appender>
<!--
<shutdownHook class="ch.qos.logback.core.hook.DelayingShutdownHook"/> -->
<root level="INFO">
<appender-ref ref="stdout"/>
</root>
</configuration>
但是在签入滚动文件时,文件中丢失了很多日志条目。
在上述情况下确实需要帮助。
任何help/suggestion真的可以帮到我很多!
终于解决了!
问题:有 2 个 JVM 试图写入一个公共文件。
所以只需在 RollingFileAppender 中添加以下内容
<prudent>true</prudent>
并在配置中删除文件参数。
<appender name="abc_req" class="ch.qos.logback.core.rolling.RollingFileAppender">
<prudent>true</prudent>
<encoder>
<pattern>%m%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log}/abc/request/request.log.%d{yyyy-MM-dd-HH}</fileNamePattern>
</rollingPolicy>
</appender>
另外,通过 rollingPolicy 中的 fileNamePattern,我能够提供正确的文件路径。