ExternallyRolledFileAppender is a specialized RollingFileAppender that allows an external process to trigger a log file rollover via a network socket. This is useful for operating system-independent, fast, and reliable log rotation.
How it works
- The appender listens on a specific TCP port.
- An external client connects to that port and sends the exact string
RollOver. - The appender performs the rollover and sends back an
OK acknowledgment.
Security Warning
The initiator is not authenticated. Anyone who can reach the specified port can trigger a rollover. In production environments, ensure you have network-level protections (like firewalls) to prevent unauthorized access.
Configuration
To use this appender, you must set the Port property in your log configuration to the desired TCP port.
Protocol Constants
- Trigger Message:
RollOver (must be sent by the client) - Acknowledgment Message:
OK (sent by the appender upon success)
# Example Log4j Configuration (Conceptual)
externallyRolledFileAppender.Port = 45678
externallyRolledFileAppender.File = /path/to/your/logfile.log
externallyRolledFileAppender.MaxFileSize = 10MB
externallyRolledFileAppender.DatePattern = "yyyy-MM-dd"