首页 > 解决方案 > log4j2:如何在不重新启动应用程序的情况下在月/日文件夹中创建日志

问题描述

我有以下 log4j2.xml 文件。在启动程序时,它会为每个月创建新文件夹。但我想登录新月文件夹(如果月份已更改),而不需要每月重新启动程序。

<RollingFile name="info-log"
             fileName="${sys:exportLoggingPath}/INFO/${date:yyyy}/${date:yyyy-MM}/Recent.log"
             filePattern="${sys:exportLoggingPath}/INFO/${date:yyyy}/${date:yyyy-MM}/%d{yyyy-MM-dd}-%i.log">
  <PatternLayout>
    <pattern>%d{yyyy-MM-dd HH:mm:ss}\t admin \t%X{itemType}\t%X{operationType}\t%m\t%X{traceID}%n</pattern>
  </PatternLayout>
  <Filters>
    <ThresholdFilter level="warn" onMatch="DENY" onMismatch="NEUTRAL" />
    <ThresholdFilter level="error" onMatch="DENY" onMismatch="NEUTRAL" />
    <ThresholdFilter level="fatal" onMatch="DENY" onMismatch="NEUTRAL" />
    <ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY" />
  </Filters>
  <Policies>
    <TimeBasedTriggeringPolicy interval="1" modulate="true" />
    <SizeBasedTriggeringPolicy size="5 MB" />
  </Policies>
  <DefaultRolloverStrategy max="9999999" />
</RollingFile>

标签: log4jlog4j2

解决方案


推荐阅读