Log Rotation
Manage log file sizes and retention with Logixlysia.
Logixlysia provides powerful log rotation capabilities to help you manage your log files efficiently. The rotation system automatically handles file size limits, time-based rotation, compression, and retention policies.
Basic Configuration
Rotation Options
Size-based Rotation
Rotate logs based on file size:
Time-based Rotation
Rotate logs based on time intervals:
Retention Policy
Configure how long to keep rotated logs:
Compression
Enable compression for rotated logs:
You can also explicitly specify the compression type (currently only gzip is supported):
Multiple Rotation Strategies
Combine different rotation strategies:
How Rotation Works
File Naming Convention
When a log file is rotated, it's renamed with a timestamp:
If compression is enabled, the file is compressed after rotation:
Rotation Triggers
Rotation occurs automatically when:
- Size threshold exceeded: File size reaches or exceeds
maxSize - Time interval elapsed: Time since last rotation reaches
interval - Manual rotation: (if implemented in your application)
Retention Management
After rotation, old files are automatically cleaned up based on maxFiles:
-
Count-based: Keep only the N most recent rotated files
-
Time-based: Keep files created within the specified time period
Empty File Handling
Empty log files are not rotated to avoid creating unnecessary rotated files.
Best Practices
-
Size Management
- Set appropriate maxSize based on traffic
- Consider disk space availability
- Monitor log growth rate
-
Retention
- Configure retention based on requirements
- Consider compliance needs
- Balance storage costs
-
Compression
- Enable compression for space savings
- Consider CPU impact
- Choose appropriate compression level
-
Monitoring
- Monitor rotation success
- Track disk space usage
- Set up alerts for issues
Example Configurations
Production Setup
Development Setup
High-Volume Setup
Supported Formats
Size Formats
The maxSize option accepts multiple formats:
- String with unit:
'10k','10m','1g'(case-insensitive) - Number (bytes):
10485760(10MB in bytes) - Decimal values:
'1.5m','0.5g'
| Format | Bytes | Description |
|---|---|---|
'1k' | 1,024 | 1 kilobyte |
'1m' | 1,048,576 | 1 megabyte |
'1g' | 1,073,741,824 | 1 gigabyte |
Interval Formats
The interval option accepts:
'1h'- Every hour'1d'- Every day (24 hours)'1w'- Every week (7 days)
You can use any number: '2h', '3d', '2w', etc.
Retention Formats
The maxFiles option accepts:
- Number: Keep last N files (e.g.,
10) - Time-based: Keep files for N days (e.g.,
'30d')
Important Notes
Performance
- Rotation checks are optimized with caching to minimize file system operations
- Time-based rotation tracks the last rotation time in memory
- Compression runs asynchronously to avoid blocking log writes
Error Handling
- Rotation failures do not crash the application
- Errors are logged to console but normal logging continues
- If rotation fails, logs continue writing to the current file
File Safety
- Atomic file operations prevent data loss during rotation
- Empty files are not rotated to avoid creating unnecessary files
- Compression only occurs after successful rotation
Troubleshooting
Rotation Not Occurring
Check that:
- File path has write permissions
- Size/interval thresholds are actually being exceeded
- No errors in console output
Disk Space Issues
If running out of disk space:
- Reduce
maxFilesretention - Increase compression (
compress: true) - Reduce
maxSizeto rotate more frequently
Compression Not Working
Ensure:
compress: trueis set (defaults to gzip compression)- System has sufficient resources for compression
- Check console for compression errors