bcpierce00 / unison

Unison file synchronizer
GNU General Public License v3.0
3.99k stars 227 forks source link

Feature Request: Auto-pruning Large Log Files #1051

Open weiT1993 opened 1 month ago

weiT1993 commented 1 month ago

When I keep Unison running for a long time, the log files could become multiple GBs large. Is there a feature to automatically rewrite the logs when they become too large?

weiT1993 commented 1 month ago

Here's a workaround.

  1. Create a shell script
    
    #!/bin/bash

Directory to check

DIR_TO_CHECK="/path/to/directory"

Size limit in bytes (e.g., 10485760 bytes = 10 MB)

SIZE_LIMIT=10485760

Infinite loop to check every 10 seconds

while true; do

Find and check all .log files

find "$DIR_TO_CHECK" -type f -name '*.log' | while read -r FILE; do
    FILE_SIZE=$(stat -f%z "$FILE")
    if [ "$FILE_SIZE" -gt "$SIZE_LIMIT" ]; then
        rm "$FILE"
        echo "$(date '+%Y-%m-%d %H:%M:%S') - Deleted $FILE (size: $FILE_SIZE bytes)" >> /path/to/watch_log_files.log
    fi
done

# Sleep for 10 seconds before checking again
sleep 10

done


2. Give script permissions: `chmod +x /path/to/watch_log_files.sh`
3. Create a LaunchAgent plist file in `~/Library/LaunchAgents/`, for example, `com.example.watch_log_files.plist`.

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

Label com.example.watch_log_files ProgramArguments /path/to/watch_log_files.sh RunAtLoad KeepAlive StandardOutPath /path/to/watch_log_files.out StandardErrorPath /path/to/watch_log_files.err


4. Launch it via `launchctl load ~/Library/LaunchAgents/com.example.watch_log_files.plist`
gdt commented 1 month ago

This is a question about what exists already. Please ask on the mailing list as the issue tracker is for bugs and validated/well-defined feature requests.

See