2017-09-26 78 views
0

當前正在使用以下屬性文件。能夠存檔基於尺寸的觸發策略。但是如果日期從一個更改爲另一個,則上一個日期的最後一個日誌文件沒有歸檔。使用TimeBasedTriggeringPolicy無法歸檔log4j2中的最後一天日誌文件

property.basePath = H:/Application/Application_Name 
appender.console.layout.pattern = %d{yyyy-MM-dd'T'hh:mm:ss.SSSXXX} %-5p [%tid] [%t] [%r] %x %c %M - %m%n 
appender.rolling.type = RollingFile 
appender.rolling.name = fileLogger 
appender.rolling.fileName=${basePath}/hello_log-${date:MM-dd-yyyy}.log 
appender.rolling.filePattern=${basePath}/$${date:yyyyMMdd}/helloSTC_log-%d{MM-dd-yyyy}-%i.log.zip 
appender.rolling.layout.type = PatternLayout 
appender.rolling.layout.pattern = %d{yyyy-MM-dd'T'hh:mm:ss.SSSXXX} %-5p [%tid] [%t] [%r] %x %c %M - %m%n 
appender.rolling.policies.type = Policies 
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy 
appender.rolling.policies.time.interval = 1 
appender.rolling.policies.time.modulate = true 
appender.rolling.policies.size.type=SizeBasedTriggeringPolicy 
appender.rolling.policies.size.size=100MB 
appender.rolling.strategy.type = DefaultRolloverStrategy 
appender.rolling.strategy.max = 100 
appender.rolling.strategy.delete.type = Delete 
appender.rolling.strategy.delete.basePath = ${basePath} 
appender.rolling.strategy.delete.maxDepth = 2 
appender.rolling.strategy.delete.ifLastModified.type = IfLastModified 
appender.rolling.strategy.delete.ifLastModified.age = 30d 
logger.application.name = com.example 
logger.application.level = info 
logger.application.additivity = false 
logger.application.appenderRef.rolling.ref = fileLogger 
rootLogger.level = error 
rootLogger.additivity = false 
rootLogger.appenderRef.rolling.ref = fileLogger 
+0

如果我從日誌文件名中刪除日期模式,那麼它正確地發生。但我需要在我的文件名中添加日期模式。 –

回答

0

您是否嘗試過僅使用SimpleDateFormat模式?

appender.rolling.fileName=${basePath}/hello_log-%d{MM-dd-yyyy}.log 
appender.rolling.filePattern=${basePath}/%d{yyyyMMdd}/helloSTC_log-%d{MM-dd-yyyy}-%i.log.zip