logback-spring.xml 如何配置cron
时间: 2023-03-07 09:37:13 浏览: 150
Logback-Spring.xml 的配置非常简单,只需要在 XML 文件中添加如下代码即可配置 cron:<cron-expression>0 0 0/1 * * ?</cron-expression>
相关问题
logback-spring.xml 配置cron
Logback-spring.xml的配置cron可以通过在logback-spring.xml文件中增加一个scheduling element来实现,这个element可以指定任务的时间间隔和任务的行为。
logback-spring.xml 配置cron定时器给出完整的logback-spring.xml配置
<configuration>
<springProfile name="production">
<timestamp key="byDay" datePattern="yyyy-MM-dd'T'HH:mm:ss.SSSZ" />
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder>
<pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>/logs/appName-%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>
</appender>
</springProfile> <springProfile name="cron">
<timestamp key="byCron" datePattern="yyyy-MM-dd'T'HH:mm:ss.SSSZ" />
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder>
<pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>/logs/appName-cron-%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>
</appender>
<cronTriggeringPolicy class="ch.qos.logback.core.rolling.CronTriggeringPolicy">
<cronExpression>0 0 0 * * ?</cronExpression>
</cronTriggeringPolicy>
</springProfile>
</configuration>
阅读全文