Log Rotation
What is Log Rotation?
Log rotation is a critical feature for managing log files in long-running applications. It prevents log files from consuming excessive disk space and provides a clean, organized way to track application logs over time.
How Log Rotation Works in Logdy
When you use the --rotate-file-size
argument, Logdy automatically manages your log files to ensure:
Automatic File Size Management
- Logs are written to a primary log file
- When the log file reaches the specified size limit, it is automatically "rotated"
- The current log file is renamed and a new log file is created
Process-Safe Rotation
Logdy's log rotation is designed to be robust and safe, even if the application is unexpectedly stopped or restarted:
- Ensures no log data is lost during rotation
- Handles incomplete rotations gracefully
- Maintains log file integrity across application restarts
Using Log Rotation
To enable log rotation, use the --rotate-file-size
argument when starting Logdy:
TIP
You need to use --append-to-file
option to start storing logs in a file
bash
logdy --append-to-file=logdy.log --rotate-file-size 10M # Rotate logs when they reach 10 megabytes
Benefits
- Prevents individual log files from growing too large
- Helps manage disk space efficiently
- Provides a clean history of application logs
- Ensures continuous logging without manual intervention
Example Rotation Scenario
- Start Logdy with
--append-to-file=logdy.log --rotate-file-size 10M
- Logs are written to
logdy.log
- When
logdy.log
reaches 10MB:- Current
logdy.log
is renamed tologdy.1.log
- A new
logdy.log
is created for future logs
- Current
This process continues automatically, helping you maintain organized and manageable log files.