Compare commits

...

3 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
0d31071e18 Update documentation to reflect implemented changes
- Clarify that size-based rotation is already implemented
- Update line numbers to match actual code location (line 407)
- Mark patch as reference since changes are already applied
- Remove misleading "recommended enhancement" language

Co-authored-by: rustdesk <71636191+rustdesk@users.noreply.github.com>
2026-01-29 06:46:30 +00:00
copilot-swe-agent[bot]
b2444dee9a Add size-based log rotation and documentation
- 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>
2026-01-29 06:43:43 +00:00
copilot-swe-agent[bot]
f2e2680f37 Initial plan 2026-01-29 06:35:54 +00:00
4 changed files with 151 additions and 1 deletions

79
docs/LOG_MANAGEMENT.md Normal file
View File

@@ -0,0 +1,79 @@
# 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`) uses size-based rotation:
```rust
.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
1. **Bounded Disk Usage**: Maximum log storage becomes ~3.1GB (31 files × 100MB)
2. **Maintained Organization**: Daily rotation still occurs for time-based organization
3. **Prevents Runaway Logs**: Heavy activity days can't create multi-gigabyte single files
4. **Automatic Cleanup**: Old files still automatically deleted after 31 days
### Implementation
The implementation is in the `hbb_common` library:
**File**: `libs/hbb_common/src/lib.rs`
**Function**: `init_log()`
**Line**: ~407
```diff
- 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:
1. Logs older than 31 days are automatically deleted
2. Individual files never exceed the configured size limit
3. Total disk usage is bounded and predictable
## Testing
To verify the rotation works correctly:
1. Check log directory before and after rotation
2. Verify old files are cleaned up after 31 days
3. Monitor file sizes don't exceed the configured limit
4. 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`

39
docs/patches/README.md Normal file
View File

@@ -0,0 +1,39 @@
# Patches for hbb_common
This directory contains patches for reference. The changes described have already been applied to the `hbb_common` submodule in this PR.
## hbb_common-log-rotation.patch
**Status**: ✅ Already applied in this PR (submodule commit 0c401fd)
**Purpose**: Add size-based log rotation to prevent excessive disk usage
**Apply to**: `libs/hbb_common` submodule
**Target repository**: https://github.com/rustdesk/hbb_common
### Reference Information
This patch file is provided for:
- Documentation of the exact changes made
- Reference for maintainers
- Potential cherry-picking to other branches if needed
The changes have already been implemented in the submodule updated by this PR.
### What it does
- Changes log rotation from age-only to age-or-size based
- Rotates logs when they reach 100MB OR daily (whichever comes first)
- Limits total log storage to ~3.1GB (31 files × 100MB max each)
- Prevents runaway log files from consuming excessive disk space
### Testing
After applying the patch and rebuilding:
1. Verify logs are created in the standard location
2. Check that individual log files don't exceed 100MB
3. Confirm old files are still cleaned up after 31 days
4. Ensure log content is still complete and useful
See `../LOG_MANAGEMENT.md` for complete documentation.

View File

@@ -0,0 +1,32 @@
From: GitHub Copilot <github-copilot@github.com>
Subject: [PATCH] Add size-based log rotation to prevent excessive disk usage
This patch adds size-based rotation to the flexi_logger configuration
to prevent individual log files from growing unbounded. Logs will now
rotate when they reach 100MB OR daily (whichever comes first).
With the existing 31-file cleanup policy, this limits total log storage
to approximately 3.1GB, preventing excessive disk space consumption.
---
src/lib.rs | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/lib.rs b/src/lib.rs
index d9713b9..ba21e90 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -402,7 +402,9 @@ pub fn init_log(_is_async: bool, _name: &str) -> Option<flexi_logger::LoggerHand
})
.format(opt_format)
.rotate(
- 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),
Naming::Timestamps,
Cleanup::KeepLogFiles(31),
)
--
2.43.0