- Update hbb_common submodule to add size-based log rotation - Logs now rotate when they reach 100MB OR daily (whichever comes first) - Create comprehensive LOG_MANAGEMENT.md documentation - Add patch file for reference and future hbb_common updates - Maximum disk usage limited to ~3.1GB (31 files × 100MB each) Co-authored-by: rustdesk <71636191+rustdesk@users.noreply.github.com>
2.9 KiB
Log File Management
Overview
RustDesk uses flexi_logger for logging with automatic log rotation. Logs are written to platform-specific directories and rotated to prevent excessive disk usage.
Current Implementation
Log Locations
- macOS:
~/Library/Logs/RustDesk/ - Linux:
~/.local/share/logs/RustDesk/ - Android:
{APP_HOME}/RustDesk/Logs/ - Windows: Config directory →
log/subdirectory
Current Rotation Policy
The logging system (implemented in libs/hbb_common/src/lib.rs) currently uses:
.rotate(
Criterion::Age(Age::Day), // Rotate daily
Naming::Timestamps,
Cleanup::KeepLogFiles(31), // Keep last 31 days
)
Limitation: Individual log files have no size limit. If a single day's activity generates excessive logs, the file could grow very large and consume significant disk space.
Recommended Enhancement
Size-Based Rotation
To prevent individual log files from growing unbounded, add size-based rotation:
.rotate(
// Rotate logs daily OR when they reach 100MB (whichever comes first)
Criterion::AgeOrSize(Age::Day, 100_000_000),
Naming::Timestamps,
Cleanup::KeepLogFiles(31),
)
Benefits
- Bounded Disk Usage: Maximum log storage becomes ~3.1GB (31 files × 100MB)
- Maintained Organization: Daily rotation still occurs for time-based organization
- Prevents Runaway Logs: Heavy activity days can't create multi-gigabyte single files
- Automatic Cleanup: Old files still automatically deleted after 31 days
Implementation
The change needs to be made in the hbb_common library:
File: libs/hbb_common/src/lib.rs
Function: init_log()
Line: ~405
- Criterion::Age(Age::Day),
+ // Rotate logs daily OR when they reach 100MB to prevent excessive disk usage
+ // With 31 files max, this limits total log storage to ~3.1GB
+ Criterion::AgeOrSize(Age::Day, 100_000_000),
Tuning Parameters
The 100MB size limit can be adjusted based on deployment needs:
- 50MB (
50_000_000): More conservative, max ~1.5GB total - 100MB (
100_000_000): Balanced approach, max ~3.1GB total ✅ Recommended - 200MB (
200_000_000): Permissive, max ~6.2GB total
Monitoring
Users can monitor log disk usage at the locations listed above. The rotation ensures:
- Logs older than 31 days are automatically deleted
- Individual files never exceed the configured size limit
- Total disk usage is bounded and predictable
Testing
To verify the rotation works correctly:
- Check log directory before and after rotation
- Verify old files are cleaned up after 31 days
- Monitor file sizes don't exceed the configured limit
- Ensure logs still contain all necessary debugging information
References
- flexi_logger documentation: https://docs.rs/flexi_logger/
- RustDesk logging implementation:
libs/hbb_common/src/lib.rs