user18121839
user18121839

Reputation: 1

half-daily rollover in log4j2

Half-daily rollover for log4j2 not working for the given propertie file.

status = error
name = Proper

property.filepath = C\:/xi/doc/home/new/log
property.filename1 = ${filepath}/Common.log

filter.threshold.type = ThresholdFilter
filter.threshold.level = debug

appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %5p [%C].%M %m %n

appender.rolling1.type = RollingFile
appender.rolling1.name = RollingFile1
appender.rolling1.fileName = ${filename1}
appender.rolling1.filePattern = ${filepath}/Common.%d{yyyy-MM-dd-a}.%i.log.gz
appender.rolling1.layout.type = PatternLayout
appender.rolling1.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %5p [%C].%M %m %n
appender.rolling1.policies.type = Policies
appender.rolling1.policies.time.type = TimeBasedTriggeringPolicy
appender.rolling1.policies.time.interval = 1
appender.rolling1.policies.time.modulate = true
appender.rolling1.policies.size.type = SizeBasedTriggeringPolicy
appender.rolling1.policies.size.size = 100MB
appender.rolling1.strategy.type = DefaultRolloverStrategy
appender.rolling1.strategy.max = 20
appender.rolling1.strategy.delete.type = Delete
appender.rolling1.strategy.delete.basePath = ${basePath}
appender.rolling1.strategy.delete.maxDepth = 10
appender.rolling1.strategy.delete.ifLastModified.type = IfLastModified

# Delete all files older than 1 day
appender.rolling1.strategy.delete.ifLastModified.age = 1d

# loggers
logger.name = common
logger.level = debug
logger.additivity = false
logger.appenderRefs = rolling1
logger.appenderRefs.level = debug
logger.appenderRef.rolling1.ref = RollingFile1

The rollover works hourly and minutely if interval given and filepattern is given as ${filepath}/Common.%d{yyyy-MM-dd-HH} and ${filepath}/Common.%d{yyyy-MM-HH-minutely}

How to rollover half-daily? Is it supported in log4j2?

Upvotes: 0

Views: 427

Answers (1)

Piotr P. Karwasz
Piotr P. Karwasz

Reputation: 16045

Log4j 1.x used to check at every message if the file pattern resolved to a different file name and rotated if it did.

However Log4j 2.x uses another approach. The date pattern is used twofold:

  • the date pattern %d{yyyy-MM-dd-a} is used to determine the rollover frequency (cf. source code), which in this case is days. This determines the time of the next rollover.
  • the date pattern is also used to determine the name of the file, which would contains AM in the morning and PM in the afternoon.

If you want two daily rotations you really need to add an hour specifier to the pattern: e.g. %d{yyyy-MM-dd-Ka} and set interval to 12.

Upvotes: 0

Related Questions