mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-02-17 14:07:28 +08:00
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>
This commit is contained in:
95
docs/LOG_MANAGEMENT.md
Normal file
95
docs/LOG_MANAGEMENT.md
Normal file
@@ -0,0 +1,95 @@
|
||||
# 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:
|
||||
|
||||
```rust
|
||||
.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:
|
||||
|
||||
```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 change needs to be made in the `hbb_common` library:
|
||||
|
||||
**File**: `libs/hbb_common/src/lib.rs`
|
||||
**Function**: `init_log()`
|
||||
**Line**: ~405
|
||||
|
||||
```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`
|
||||
47
docs/patches/README.md
Normal file
47
docs/patches/README.md
Normal file
@@ -0,0 +1,47 @@
|
||||
# Patches for hbb_common
|
||||
|
||||
This directory contains patches that should be applied to the `hbb_common` library submodule.
|
||||
|
||||
## hbb_common-log-rotation.patch
|
||||
|
||||
**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
|
||||
|
||||
### How to apply
|
||||
|
||||
#### Option 1: Apply in hbb_common repository
|
||||
|
||||
```bash
|
||||
cd /path/to/hbb_common
|
||||
git apply /path/to/rustdesk/docs/patches/hbb_common-log-rotation.patch
|
||||
git commit -m "Add size-based log rotation to prevent excessive disk usage"
|
||||
```
|
||||
|
||||
#### Option 2: Apply in rustdesk repository submodule
|
||||
|
||||
```bash
|
||||
cd libs/hbb_common
|
||||
git apply ../../docs/patches/hbb_common-log-rotation.patch
|
||||
git commit -m "Add size-based log rotation to prevent excessive disk usage"
|
||||
# Note: This creates a local commit in the submodule
|
||||
```
|
||||
|
||||
### 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.
|
||||
32
docs/patches/hbb_common-log-rotation.patch
Normal file
32
docs/patches/hbb_common-log-rotation.patch
Normal 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
|
||||
|
||||
Submodule libs/hbb_common updated: 900077a2c2...0c401fd18a
Reference in New Issue
Block a user