Crates.io | log-watcher |
lib.rs | log-watcher |
version | 0.2.0 |
created_at | 2025-09-13 02:10:53.851418+00 |
updated_at | 2025-09-13 17:47:57.615099+00 |
description | Real-time log file monitoring with pattern highlighting and desktop notifications |
homepage | https://github.com/matcharr/logwatcher |
repository | https://github.com/matcharr/logwatcher |
max_upload_size | |
id | 1837138 |
size | 236,078 |
A powerful CLI tool for real-time log file monitoring with pattern highlighting and desktop notifications.
git clone https://github.com/matcharr/logwatcher.git
cd logwatcher
cargo build --release
sudo cp target/release/logwatcher /usr/local/bin/
cargo install log-watcher
Monitor a single log file for ERROR and WARN patterns:
logwatcher -f /var/log/app.log
Monitor multiple log files simultaneously:
logwatcher -f app.log -f error.log -f access.log
Specify custom patterns to match:
logwatcher -f app.log -p "ERROR,CRITICAL,timeout"
Use regular expressions for advanced matching:
logwatcher -f app.log -r -p "user_id=\d+|session_\w+"
Test patterns on existing file content:
logwatcher -f app.log --dry-run -p "ERROR,WARN"
Only show lines that match patterns:
logwatcher -f app.log -q -p "ERROR"
Flag | Short | Description |
---|---|---|
--file |
-f |
Path(s) to log file(s) to watch (can be specified multiple times) |
Flag | Short | Default | Description |
---|---|---|---|
--pattern |
-p |
ERROR,WARN |
Comma-separated patterns to match |
--regex |
-r |
false |
Treat patterns as regular expressions |
--case-insensitive |
-i |
false |
Case-insensitive pattern matching |
--color-map |
-c |
(see below) | Custom pattern:color mappings |
Flag | Short | Default | Description |
---|---|---|---|
--notify |
-n |
true |
Enable desktop notifications |
--notify-patterns |
(all patterns) | Specific patterns that trigger notifications | |
--notify-throttle |
5 |
Maximum notifications per second |
Flag | Short | Default | Description |
---|---|---|---|
--dry-run |
-d |
false |
Preview mode (no tailing, no notifications) |
--quiet |
-q |
false |
Suppress non-matching lines |
--no-color |
false |
Disable ANSI colors | |
--prefix-file |
auto |
Prefix lines with filename |
Flag | Default | Description |
---|---|---|
--poll-interval |
100 |
File polling interval in milliseconds |
--buffer-size |
8192 |
Read buffer size in bytes |
# Monitor application logs for errors
logwatcher -f /var/log/app.log
# Output:
# [2025-01-07 15:00:01] Starting application server...
# [2025-01-07 15:00:02] Database connection established
# [2025-01-07 15:00:03] ERROR Failed to bind to port 8080 # (shown in red)
# [Desktop notification appears: "ERROR detected in app.log"]
logwatcher -f app.log -f nginx.log -p "ERROR,404,timeout" --color-map "404:yellow,timeout:magenta"
# Output:
# [app.log] [2025-01-07 15:00:01] Request processed successfully
# [nginx.log] [2025-01-07 15:00:02] 404 Not Found: /api/users # (shown in yellow)
# [app.log] [2025-01-07 15:00:03] ERROR Database timeout # (shown in red, "timeout" in magenta)
logwatcher -f app.log --dry-run -p "ERROR,WARN"
# Output:
# Reading existing content from app.log...
# [DRY-RUN] Line 42: ERROR Connection refused # (shown in red)
# [DRY-RUN] Line 89: WARN Memory usage at 85% # (shown in yellow)
# Found 2 matching lines (1 ERROR, 1 WARN)
# Dry-run complete. No notifications sent.
logwatcher -f app.log -q -r -p "user_id=\d+|session_\w+"
# Output:
# [2025-01-07 15:00:01] Login successful for user_id=12345
# [2025-01-07 15:00:15] Order placed by user_id=67890
# [2025-01-07 15:00:30] Session created: session_abc123
LogWatcher automatically detects and handles log file rotation:
# LogWatcher automatically handles rotation
logwatcher -f /var/log/app.log
# When rotation occurs:
# Warning: File rotation detected for /var/log/app.log
# Info: Reopened file: /var/log/app.log
LogWatcher supports desktop notifications on Linux, macOS, and Windows:
# Enable notifications for all patterns
logwatcher -f app.log --notify
# Only notify for critical patterns
logwatcher -f app.log --notify-patterns "ERROR,FATAL,CRITICAL"
# Throttle notifications to 2 per second
logwatcher -f app.log --notify-throttle 2
# Optimize for high-frequency logs
logwatcher -f app.log --poll-interval 50 --buffer-size 16384
# Optimize for large files
logwatcher -f large.log --poll-interval 500 --buffer-size 32768
File not found:
# Check file permissions and path
ls -la /var/log/app.log
logwatcher -f /var/log/app.log
No notifications:
# Test notification system
logwatcher -f app.log --dry-run --notify -p "TEST"
High CPU usage:
# Increase polling interval
logwatcher -f app.log --poll-interval 500
Memory usage:
# Reduce buffer size
logwatcher -f app.log --buffer-size 4096
Enable debug logging:
RUST_LOG=debug logwatcher -f app.log
MIT License - see LICENSE file for details.
LogWatcher has comprehensive test coverage:
# Run all tests
cargo test
# Run only integration tests
cargo test --test integration
# Run benchmarks
cargo bench
# Check test coverage (requires cargo-tarpaulin)
cargo install cargo-tarpaulin
cargo tarpaulin --out Html
Coverage reports are automatically generated and uploaded to Codecov on every commit.