logback TimeBasedRollingPolicy似乎不适用于以下配置。
logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true" scan="true"
scanPeriod="30 seconds">
<property name="LOG_PATH" value="logs" />
<property name="LOG_ARCHIVE" value="${LOG_PATH}/bkp" />
<springProperty scope="context" name="appName" source="spring.application.name"/>
<timestamp key="timestamp-by-second"
datePattern="yyyyMMdd'T'HHmmss" />
<appender name="Console-Appender"
class="ch.qos.logback.core.ConsoleAppender">
<layout>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{36} - %msg%n</pattern>
</layout>
</appender>
<appender name="Spring-logAppender"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_PATH}/Spring.log</file>
<rollingPolicy
class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_ARCHIVE}/Spring.log%d{yyyy-MM-dd}.log
</fileNamePattern>
<maxHistory>30</maxHistory>
<totalSizeCap>50MB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [${appName},%X{X-B3-TraceId:-},%X{X-B3-SpanId:-},%X{X-Span-Export:-}] [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<appender name="Database-logAppender"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_PATH}/Database.log</file>
<rollingPolicy
class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_ARCHIVE}/Database.log%d{yyyy-MM-dd}.log
</fileNamePattern>
<maxHistory>30</maxHistory>
<totalSizeCap>50MB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [${appName},%X{X-B3-TraceId:-},%X{X-B3-SpanId:-},%X{X-Span-Export:-}] [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<logger name="org.springframework.security" level="trace"
additivity="false">
<appender-ref ref="Spring-logAppender" />
</logger>
<logger name="com.zaxxer.hikari" level="error"
additivity="false">
<appender-ref ref="Database-logAppender" />
</logger>
<logger name="org.hibernate" level="error"
additivity="false">
<appender-ref ref="Database-Appender" />
</logger>
<root level="debug">
<appender-ref ref="Spring-Appender" />
</root>
</configuration>
这有什么毛病吗?我正在使用Spring:2.1.1.RELEASE。第二天没有任何日志滚动或备份。如何检查此日志配置中是否有任何错误。
答案 0 :(得分:0)
这是我用来记录日志的方法,请尝试一下,希望对您有所帮助。
<Configuration monitorInterval="60">
<Properties>
<Property name="path">C:/pathyouwant/</Property>
<Property name="LOG_PATTERN">
%d{yyyy-MM-dd HH:mm:ss.SSS} %5p : %m%n%ex
</Property>
</Properties>
<Appenders>
<Console name="Console-Appender" target="SYSTEM_OUT">
<PatternLayout>
<pattern>
[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
</pattern>
>
</PatternLayout>
</Console>
<RollingFile name="App-Appender" fileName="${path}/app.log"
filePattern="${path}/zuul_app-%d{yyyy-MM-dd}-%i.log">
<PatternLayout>
<Pattern>${LOG_PATTERN}</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" />
</Policies>
</RollingFile>
<File name="SpringBoot-Appender" fileName="${path}/app_springboot.log">
<PatternLayout>
<pattern>
[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
</pattern>
</PatternLayout>
</File>
</Appenders>
<Loggers>
<logger name="org.springframework.security" level="trace"
additivity="false">
<appender-ref ref="Spring-logAppender" />
</logger>
<logger name="com.zaxxer.hikari" level="error"
additivity="false">
<appender-ref ref="Database-logAppender" />
</logger>
<logger name="org.hibernate" level="error"
additivity="false">
<appender-ref ref="Database-Appender" />
</logger>
<Root>
<AppenderRef ref="Console-Appender" />
</Root>
</Loggers>
</Configuration>