[英]Where to define the date/time pattern for TimeBasedTriggeringPolicy in Log4j2
I am new in Log4j2 and want to use the RollingFileAppender . 我是Log4j2的新手,想要使用RollingFileAppender 。 Further as rollover I want to use the TimeBaseTriggeringPolicy: 进一步作为翻转,我想使用TimeBaseTriggeringPolicy:
The TimeBasedTriggeringPolicy causes a rollover once the date/time pattern no longer applies to the active file. 一旦日期/时间模式不再适用于活动文件,TimeBasedTriggeringPolicy将导致翻转。
On the site above there is an example for such an TimeBasedTriggeringPolicy: 在上面的网站上有一个这样的TimeBasedTriggeringPolicy示例:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn" name="MyApp" packages="">
<Appenders>
<RollingFile name="RollingFile" fileName="logs/app.log"
filePattern="logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.gz">
<PatternLayout>
<Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="250 MB"/>
</Policies>
</RollingFile>
</Appenders>
<Loggers>
<Root level="error">
<AppenderRef ref="RollingFile"/>
</Root>
</Loggers>
</Configuration>
Where is in the configuration above the "date/time pattern" defined, that determines if the active file applies to it or not? 在定义的“日期/时间模式”上方的配置中,确定活动文件是否适用于它?
Thanks for your help! 谢谢你的帮助!
That is the filePattern. 那是filePattern。 In your config: 在你的配置中:
filePattern="logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.gz">
The most granular time unit in the above is dd
(days) so it will rollover daily at midnight. 上面最精细的时间单位是dd
(天),因此它将在午夜每天翻转。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.