log4j2 RolllingFileAppender filePattern 創建日期錯誤 (log4j2 RolllingFileAppender filePattern create a wrong date)


問題描述

log4j2 RolllingFileAppender filePattern 創建日期錯誤 (log4j2 RolllingFileAppender filePattern create a wrong date)

我在 filePattern 中使用了日期,但是 log4j 創建的日期不正確。今天是2015‑11‑23,但是log4j創建了一個名為2015‑12的文件目錄。我的 log4j2 版本是 2.4.1。這是一個快照

下面是我的 log4j2 配置。</電話>

<RollingFile name="RollingFile" fileName="logs/executor.log" append="true"
                 filePattern="logs/$${date:yyyy‑MM}/executor‑%d{yyyy‑‑MM‑‑dd}‑%i.log.gz">
      <PatternLayout>
        <Pattern>%t  %d{yyyy‑MM‑dd HH:mm:ss} %c %p ‑%m%n</Pattern>
      </PatternLayout>
      <Policies>
        <TimeBasedTriggeringPolicy interval="24" modulate="true"/>
        <SizeBasedTriggeringPolicy size="1MB"/>
      </Policies>
    </RollingFile>

參考解法

方法 1:

This issue is due to your intervals. Its effectively setting up the initial rollover file to be when the end of the next rollover would be. The documentation on the RollingFileAppender for the TimeBasedTriggeringPolicy says: "How often a rollover should occur based on the most specific time unit in the date pattern." Since your most specific time unit is dd, or day of month, its setting it up for 24 days from 2015‑11‑23, or sometime in month 12, when it would rollover.

What you probably want is an interval of 1. This should rollover each file day and then once a month spills over, it would into the next subfolder because 1 day was triggered.

I've tested this with your pattern, but use a MM at the end and and a interval="24." Modulated, it rolled into 12/2016, but not modulated, it rolled over saying 11/2017! I can't say why and per my comment above, there have been issues with this feature reported.

方法 2:

Have same problem.

<RollingFile name="DailyFileAppender" fileName="logs/server.log"
                 filePattern="logs/server ‑ %d{yyyy‑MM‑dd} ‑ %i.log">
        <PatternLayout>
            <pattern>%d{yyyy‑MM‑dd HH:mm:ss,SSS}‑ %c{1}: %m%n</pattern>
        </PatternLayout>
        <Policies>
            <TimeBasedTriggeringPolicy interval="5"/>
            <SizeBasedTriggeringPolicy size="10 KB"/>
        </Policies>
        <DefaultRolloverStrategy max="4"/>
    </RollingFile>

The output file's data is wrong. example the date is "2015‑12‑01" the output date is "2015‑12‑05"

(by chowAdam MarcionekTinyZ)

參考文件

  1. log4j2 RolllingFileAppender filePattern create a wrong date (CC BY‑SA 2.5/3.0/4.0)

#log4j2






相關問題

Làm cách nào để thêm phần phụ Log4J2 vào thời gian chạy theo chương trình? (How to add Log4J2 appenders at runtime programmatically?)

使用 Spring 和 Log4j2 的 Classloader-Leak (Classloader-Leak with Spring and Log4j2)

log4j2 RolllingFileAppender filePattern 創建日期錯誤 (log4j2 RolllingFileAppender filePattern create a wrong date)

將時間戳添加到日誌文件名時出錯 (log4j2) (Error adding timestamp to log file name (log4j2))

log4j2 - 以編程方式更改 RollingFileAppender 的最大文件大小 (log4j2 - programmatically change max file size of RollingFileAppender)

log4j 沒有登錄到文件或控制台 (log4j is not logging into file or console)

Log4j2 未在 Linux 中使用 Spring Boot 創建日誌文件 (Log4j2 not creating log file with Spring Boot in Linux)

application.properties 中的外部 log4j2.xml 文件路徑 (External log4j2.xml file path in application.properties)

使用 Spring 的依賴於配置文件的 log4j2 配置 (Profile-dependent log4j2 configuration with Spring)

從 log4j2.xml 訪問環境變量 (Accessing environment variable from log4j2.xml)

Spring Boot 應用程序中的內部 tomcat 停止響應調用 (internal tomcat inside spring boot application stops responding to calls)

如何在 mule 應用程序中實現 log4j2 (2.14.0) 'JSON 模板佈局'? (How can I implement log4j2 (2.14.0) 'JSON Template Layout' in a mule application?)







留言討論