This project provides Log4j2 Plugin capable of rotating logs at the end of given time period (hour, day, etc).
See an exemplary log4j2.xml (src/main/resources/log4j2.xml) for how the plugin is used.
How it works:
- FTimeBasedTriggeringPolicy is a copy-paste TimeBasedTriggeringPolicy policy that exposes RollingFileManager instance as well as checkRollover method
- FTimeBasedTriggeringPolicy allows 0-length files to be rotated
- FTimeBasedTriggeringPolicy instance registers itself in the LogRotateThread during initialization
- Every few minutes LogRotateThread queries FTimeBasedTriggeringPolicy.checkRollover method which if needed will trigger log rotation
How-to:
- Register FTimeBasedTriggeringPolicy in the tag
- Start LogRotateThread
- If using Routing, make sure to "pre-initialize" log appenders by calling LogRotateThread.initializeAppenders method
Licensed under the Apache License, Version 2.0
http://www.apache.org/licenses/LICENSE-2.0