gpt4 book ai didi

java - Log4j 2 中的文件模式有什么用?

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:45:49 25 4
gpt4 key购买 nike

我对 log4j 2 中 RollingFile Appender 的文件模式有疑问。RollingFile 需要一个 FileName 和 FilePattern,但我不知道 FilePattern 的作用。我认为它只是被忽略了。这是我的 log4j2.xml 的一部分

<Property name="pattern">
%-5p [%d{dd.MM.yyyy - HH:mm:ss}] : %m%n %ex
</Property>

<Property name="MainLoggerPath">
C:/logs/MainLogger.log
</Property>

<Property name="FilePattern">
C:/logs/$${date:yyyy-MM}/app-%d{MM- dd-yyyy}-%i.log.gz
</Property>


<RollingFile name="MainAppender" fileName="${MainLoggerPath}"
filePattern="${FilePattern}">

<ThresholdFilter level="ALL" onMatch="ACCEPT" onMismatch="DENY" />

<PatternLayout
pattern="${pattern}" />

<Policies>
<SizeBasedTriggeringPolicy size="10 MB" />
</Policies>

<DefaultRolloverStrategy max="10" />

</RollingFile>

最佳答案

关于 documentation :

The pattern of the file name of the archived log file. The format of the pattern is dependent on the RolloverPolicy that is used. The DefaultRolloverPolicy will accept both a date/time pattern compatible with SimpleDateFormat and/or a %i which represents an integer counter. The pattern also supports interpolation at runtime so any of the Lookups (such as the DateLookup can be included in the pattern.

关于java - Log4j 2 中的文件模式有什么用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26710658/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com