v0.1.1 - Improve logging system with rotation and separate error logs
### Changed - Implement professional logging system with RotatingFileHandler - Move logs from data/ to separate logs/ directory - Add separate error.log with full tracebacks - Configure automatic log rotation (10MB max, 5 backups) - Add configurable log size and rotation settings - Improve console output format ### Configuration - New logging options in config.yaml: - max_bytes: 10485760 (10MB) - backup_count: 5 - error_file: separate error log path ### Files - logs/watchdog.log - Main log (all messages) - logs/error.log - Error log (errors only with traceback) - Auto-rotation: *.log.1-5 backups Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
c50e0d7c47
commit
30a72f5fa3
|
|
@ -19,13 +19,12 @@ ENV/
|
|||
data/*.db
|
||||
data/*.log
|
||||
data/backup.db
|
||||
logs/*.log
|
||||
logs/*.log.*
|
||||
|
||||
# Sensitive Config (optional - keep structure but remove secrets)
|
||||
# config/config.yaml
|
||||
|
||||
# Docker
|
||||
*.log
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
|
|
|||
33
CHANGELOG.md
33
CHANGELOG.md
|
|
@ -17,6 +17,36 @@ Das Format basiert auf [Keep a Changelog](https://keepachangelog.com/de/1.0.0/).
|
|||
|
||||
---
|
||||
|
||||
## [0.1.1] - 2026-02-16
|
||||
|
||||
### Changed - Verbesserte Funktionalität
|
||||
|
||||
- 📝 **Verbessertes Logging-System**
|
||||
- Separates `logs/` Verzeichnis (statt `data/`)
|
||||
- Automatische Log-Rotation mit `RotatingFileHandler`
|
||||
- Maximale Größe: 10 MB pro Datei
|
||||
- Backup-Count: 5 Dateien
|
||||
- Separate Error-Logs (`error.log`) mit vollständigem Traceback
|
||||
- Konfigurierbare Log-Größe und Rotation in `config.yaml`
|
||||
- Bessere Console-Ausgabe (kürzeres Format)
|
||||
|
||||
### Technical Details
|
||||
- `app/main.py`: Implementierung von RotatingFileHandler
|
||||
- `config/config.yaml`: Neue Logging-Optionen (max_bytes, backup_count, error_file)
|
||||
- `docker-compose.yml`: Volume-Mapping für logs/ Verzeichnis
|
||||
- `.gitignore`: Log-Dateien und Rotationen ausgeschlossen
|
||||
|
||||
### Dateien
|
||||
```
|
||||
logs/
|
||||
├── watchdog.log # Haupt-Log (alle Meldungen)
|
||||
├── watchdog.log.1-5 # Rotierte Backups
|
||||
├── error.log # Error-Log (nur Fehler)
|
||||
└── error.log.1-5 # Rotierte Error-Backups
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## [0.1.0] - 2024-02-16
|
||||
|
||||
### Added - Neue Features
|
||||
|
|
@ -109,5 +139,6 @@ watchdog-docker/
|
|||
- **Fixed** - Bugfixes
|
||||
- **Security** - Sicherheits-Fixes
|
||||
|
||||
[Unreleased]: https://tea.ffw-ak-ff.de/FFW-VG-AK-FF/watchdog-docker/compare/v0.1.0...HEAD
|
||||
[Unreleased]: https://tea.ffw-ak-ff.de/FFW-VG-AK-FF/watchdog-docker/compare/v0.1.1...HEAD
|
||||
[0.1.1]: https://tea.ffw-ak-ff.de/FFW-VG-AK-FF/watchdog-docker/compare/v0.1.0...v0.1.1
|
||||
[0.1.0]: https://tea.ffw-ak-ff.de/FFW-VG-AK-FF/watchdog-docker/releases/tag/v0.1.0
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ All settings in `config/config.yaml`:
|
|||
- Web port, secret key, admin password hash
|
||||
- SMTP settings, recipients
|
||||
- Database path, retention days
|
||||
- Logging level
|
||||
- **Logging:** level (DEBUG/INFO/WARNING/ERROR), file paths, rotation settings
|
||||
|
||||
## Important Notes
|
||||
|
||||
|
|
@ -112,6 +112,7 @@ All settings in `config/config.yaml`:
|
|||
- **Email Logic:** Only send emails for unknown devices (new_device event with known=False)
|
||||
- **Retention:** Old events auto-cleanup based on retention_days (default 90)
|
||||
- **Password:** Admin password must be werkzeug scrypt hash in config.yaml
|
||||
- **Logging:** Uses RotatingFileHandler with separate main log and error log, auto-rotation at 10MB
|
||||
|
||||
## Versioning
|
||||
|
||||
|
|
|
|||
73
README.md
73
README.md
|
|
@ -153,6 +153,8 @@ watchdog-docker/
|
|||
├── docker-compose.yml # Docker Compose Konfiguration
|
||||
├── requirements.txt # Python Dependencies
|
||||
├── README.md # Diese Datei
|
||||
├── VERSION # Aktuelle Version
|
||||
├── CHANGELOG.md # Versionshistorie
|
||||
├── config/
|
||||
│ └── config.yaml # Hauptkonfiguration
|
||||
├── app/
|
||||
|
|
@ -164,9 +166,12 @@ watchdog-docker/
|
|||
│ └── templates/
|
||||
│ ├── login.html # Login-Seite
|
||||
│ └── dashboard.html # Dashboard
|
||||
└── data/ # Auto-generiert beim ersten Start
|
||||
├── watchdog.db # SQLite Datenbank
|
||||
└── watchdog.log # Log-Datei
|
||||
├── data/ # Datenbank (auto-generiert)
|
||||
│ └── watchdog.db # SQLite Datenbank
|
||||
└── logs/ # Log-Dateien (auto-generiert)
|
||||
├── watchdog.log # Haupt-Log (mit Rotation)
|
||||
├── error.log # Error-Log (nur Fehler)
|
||||
└── *.log.* # Rotierte Backups (bis zu 5 pro Typ)
|
||||
```
|
||||
|
||||
## API Endpoints
|
||||
|
|
@ -231,13 +236,66 @@ Jede E-Mail enthält:
|
|||
- IP, MAC, Hostname (bei Geräten)
|
||||
- Detaillierte Beschreibung
|
||||
|
||||
## Logging-System
|
||||
|
||||
### Log-Dateien
|
||||
|
||||
Das System erstellt separate Log-Dateien im `logs/` Verzeichnis:
|
||||
|
||||
| Datei | Inhalt | Log-Level |
|
||||
|-------|--------|-----------|
|
||||
| `watchdog.log` | Alle Meldungen (INFO, WARNING, ERROR) | Konfigurierbar |
|
||||
| `error.log` | Nur Fehler mit vollständigem Traceback | ERROR + |
|
||||
|
||||
### Automatische Log-Rotation
|
||||
|
||||
- **Maximale Größe:** 10 MB pro Log-Datei
|
||||
- **Backup-Count:** 5 rotierte Dateien
|
||||
- **Gesamt:** ~50 MB pro Log-Typ (6 Dateien inkl. aktuellem)
|
||||
|
||||
Alte Logs werden automatisch als `.log.1`, `.log.2`, etc. archiviert.
|
||||
|
||||
### Log-Level Konfiguration
|
||||
|
||||
In `config/config.yaml`:
|
||||
|
||||
```yaml
|
||||
logging:
|
||||
level: "INFO" # Optionen: DEBUG, INFO, WARNING, ERROR, CRITICAL
|
||||
```
|
||||
|
||||
**Empfohlene Einstellungen:**
|
||||
- **Produktion:** `INFO` - Normale Betriebsmeldungen
|
||||
- **Debugging:** `DEBUG` - Detaillierte Informationen für Fehlersuche
|
||||
- **Minimal:** `WARNING` - Nur Warnungen und Fehler
|
||||
|
||||
### Log-Ansicht
|
||||
|
||||
```bash
|
||||
# Aktuelle Logs ansehen
|
||||
tail -f logs/watchdog.log
|
||||
|
||||
# Nur Fehler ansehen
|
||||
tail -f logs/error.log
|
||||
|
||||
# Docker Logs (Container)
|
||||
docker-compose logs -f watchdog
|
||||
|
||||
# Letzte 100 Zeilen
|
||||
tail -n 100 logs/watchdog.log
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Container startet nicht
|
||||
|
||||
```bash
|
||||
# Logs prüfen
|
||||
docker-compose logs
|
||||
# Container Logs prüfen
|
||||
docker-compose logs -f
|
||||
|
||||
# Lokale Log-Dateien prüfen
|
||||
tail -f logs/watchdog.log
|
||||
tail -f logs/error.log
|
||||
|
||||
# Container Status
|
||||
docker-compose ps
|
||||
|
|
@ -293,6 +351,11 @@ docker-compose ps
|
|||
logging:
|
||||
level: "DEBUG"
|
||||
```
|
||||
Danach Container neu starten und Logs prüfen:
|
||||
```bash
|
||||
docker-compose restart
|
||||
tail -f logs/watchdog.log
|
||||
```
|
||||
|
||||
## Update
|
||||
|
||||
|
|
|
|||
49
app/main.py
49
app/main.py
|
|
@ -20,14 +20,49 @@ with open('config/config.yaml', 'r') as f:
|
|||
config = yaml.safe_load(f)
|
||||
|
||||
# Setup logging
|
||||
logging.basicConfig(
|
||||
level=getattr(logging, config['logging']['level']),
|
||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||
handlers=[
|
||||
logging.FileHandler(config['logging']['file']),
|
||||
logging.StreamHandler()
|
||||
]
|
||||
from logging.handlers import RotatingFileHandler
|
||||
import os
|
||||
|
||||
# Create logs directory if it doesn't exist
|
||||
logs_dir = os.path.dirname(config['logging']['file'])
|
||||
if logs_dir and not os.path.exists(logs_dir):
|
||||
os.makedirs(logs_dir, exist_ok=True)
|
||||
|
||||
# Main log file with rotation
|
||||
main_handler = RotatingFileHandler(
|
||||
config['logging']['file'],
|
||||
maxBytes=config['logging'].get('max_bytes', 10 * 1024 * 1024), # 10MB default
|
||||
backupCount=config['logging'].get('backup_count', 5)
|
||||
)
|
||||
main_handler.setLevel(getattr(logging, config['logging']['level']))
|
||||
main_handler.setFormatter(logging.Formatter(
|
||||
'%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
||||
))
|
||||
|
||||
# Error log file (separate file for errors only)
|
||||
error_handler = RotatingFileHandler(
|
||||
config['logging']['error_file'],
|
||||
maxBytes=config['logging'].get('max_bytes', 10 * 1024 * 1024),
|
||||
backupCount=config['logging'].get('backup_count', 5)
|
||||
)
|
||||
error_handler.setLevel(logging.ERROR)
|
||||
error_handler.setFormatter(logging.Formatter(
|
||||
'%(asctime)s - %(name)s - %(levelname)s - %(message)s - [%(pathname)s:%(lineno)d]'
|
||||
))
|
||||
|
||||
# Console handler
|
||||
console_handler = logging.StreamHandler()
|
||||
console_handler.setLevel(getattr(logging, config['logging']['level']))
|
||||
console_handler.setFormatter(logging.Formatter(
|
||||
'%(asctime)s - %(levelname)s - %(message)s'
|
||||
))
|
||||
|
||||
# Configure root logger
|
||||
logging.basicConfig(
|
||||
level=logging.DEBUG, # Capture everything, handlers filter
|
||||
handlers=[main_handler, error_handler, console_handler]
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Initialize Flask
|
||||
|
|
|
|||
|
|
@ -56,7 +56,16 @@ database:
|
|||
path: "/app/data/watchdog.db"
|
||||
retention_days: 90 # Keep events for 90 days
|
||||
|
||||
# Logging
|
||||
# Logging Configuration
|
||||
logging:
|
||||
level: "INFO" # DEBUG, INFO, WARNING, ERROR
|
||||
file: "/app/data/watchdog.log"
|
||||
level: "INFO" # DEBUG, INFO, WARNING, ERROR, CRITICAL
|
||||
|
||||
# Main log file (all messages)
|
||||
file: "/app/logs/watchdog.log"
|
||||
|
||||
# Error log file (errors only with full traceback)
|
||||
error_file: "/app/logs/error.log"
|
||||
|
||||
# Log rotation settings
|
||||
max_bytes: 10485760 # 10MB per log file
|
||||
backup_count: 5 # Keep 5 backup files (total ~50MB per log type)
|
||||
|
|
@ -10,6 +10,7 @@ services:
|
|||
volumes:
|
||||
- ./config/config.yaml:/app/config/config.yaml:ro
|
||||
- ./data:/app/data
|
||||
- ./logs:/app/logs
|
||||
environment:
|
||||
- TZ=Europe/Berlin
|
||||
- PYTHONUNBUFFERED=1
|
||||
|
|
|
|||
Loading…
Reference in New Issue