【问题标题】:What is a Filepattern in Log4j 2 for?Log4j 2 中的文件模式有什么用?
【发布时间】:2014-12-29 21:32:44
【问题描述】:

我对 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>    

【问题讨论】:

    标签: java apache logging log4j2


    【解决方案1】:

    关于documentation

    归档日志文件的文件名模式。的格式 该模式取决于所使用的 RolloverPolicy。 DefaultRolloverPolicy 将接受日期/时间模式 与 SimpleDateFormat 和/或 %i 兼容,它代表一个 整数计数器。该模式还支持在运行时插值,所以 任何查找(例如 DateLookup 可以包含在 模式。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-11
      • 1970-01-01
      • 2015-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-25
      • 1970-01-01
      相关资源
      最近更新 更多