Compare commits

..

2 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
1274935106 Fix macOS build: Remove @available check causing linker error
The @available check in GetDisplayName was causing the linker to look for
__isPlatformVersionAtLeast symbol which is not available when targeting
macOS 10.14. Since this function is only used for logging, we simplify it
to return "Unknown" for all displays, avoiding the runtime availability check.

Co-authored-by: rustdesk <71636191+rustdesk@users.noreply.github.com>
2026-01-28 08:49:42 +00:00
copilot-swe-agent[bot]
85b3ed5276 Initial plan 2026-01-28 08:47:32 +00:00
5 changed files with 16 additions and 153 deletions

View File

@@ -1,79 +0,0 @@
# 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`

View File

@@ -1,39 +0,0 @@
# 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

@@ -1,32 +0,0 @@
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

View File

@@ -357,6 +357,16 @@ static std::string GetDisplayUUID(CGDirectDisplayID displayId) {
return "";
}
// Helper function to get display name from DisplayID
static std::string GetDisplayName(CGDirectDisplayID displayId) {
// Note: NSScreen.localizedName is only available on macOS 10.15+
// Since we target 10.14, we avoid using @available checks that would
// require __isPlatformVersionAtLeast runtime function.
// For now, we just return "Unknown" for all displays.
// This is only used for logging purposes, so it doesn't affect functionality.
return "Unknown";
}
// Helper function to find DisplayID by UUID from current online displays
static CGDirectDisplayID FindDisplayIdByUUID(const std::string& targetUuid) {
uint32_t count = 0;
@@ -394,7 +404,9 @@ static bool RestoreAllGammas() {
const CGGammaValue* blue = green + sampleCount;
CGError error = CGSetDisplayTransferByTable(d, sampleCount, red, green, blue);
if (error != kCGErrorSuccess) {
NSLog(@"Failed to restore gamma for display (ID: %u, UUID: %s, error: %d)", (unsigned)d, uuid.c_str(), error);
std::string displayName = GetDisplayName(d);
NSLog(@"Failed to restore gamma for display (Name: %s, ID: %u, UUID: %s, error: %d)",
displayName.c_str(), (unsigned)d, uuid.c_str(), error);
allSuccess = false;
}
}
@@ -874,7 +886,8 @@ extern "C" bool MacSetPrivacyMode(bool on) {
blackoutAttemptCount++;
CGError error = CGSetDisplayTransferByTable(d, capacity, zeros.data(), zeros.data(), zeros.data());
if (error != kCGErrorSuccess) {
NSLog(@"MacSetPrivacyMode: Failed to blackout display (ID: %u, UUID: %s, error: %d)", (unsigned)d, uuid.c_str(), error);
std::string displayName = GetDisplayName(d);
NSLog(@"MacSetPrivacyMode: Failed to blackout display (Name: %s, ID: %u, UUID: %s, error: %d)", displayName.c_str(), (unsigned)d, uuid.c_str(), error);
} else {
blackoutSuccessCount++;
}