Here a my log4j2 file. A new log file will be created when the log file meet the policies. And the file name are specified in the appender.rolling.filePattern
, The system will create a new file everyday because of the %d{yyyy-MM-dd}
and the appender.rolling.policies.time.interval=1
. You can add more on %d{yyyy-MM-dd-HH}
and the log file will be generated every hour.
name=PropertiesConfig
property.filename= ./logs
appenders= rolling
appender.rolling.type=RollingFile
appender.rolling.name=RollingFile
appender.rolling.fileName=${filename}/here-are-my-log-propertieslogs.log
appender.rolling.layout.type=PatternLayout
appender.rolling.filePattern=${filename}/feedback-propertieslogs-%d{yyyy-MM-dd}-%i.log
appender.rolling.layout.pattern=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1}:%L - %msg%n
# Rotate log file each day and keep 30 days worth
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=5MB
appender.rolling.strategy.type=DefaultRolloverStrategy
appender.rolling.strategy.max=31
appender.rolling.strategy.delete.type=Delete
appender.rolling.strategy.delete.basePath=${filename}
appender.rolling.strategy.delete.maxDepth=1
appender.rolling.strategy.delete.ifLastModified.type=IfLastModified
appender.rolling.strategy.delete.ifLastModified.age=30d
appender.rolling.strategy.delete.ifAccumulatedFileCount.type=IfAccumulatedFileCount
appender.rolling.strategy.delete.ifAccumulatedFileCount.exceeds=30
appender.rolling.strategy.delete.ifAccumulatedFileSize.type=IfAccumulatedFileSize
appender.rolling.strategy.delete.ifAccumulatedFileSize.exceeds=100MB