HBlink4 implements a comprehensive logging system with daily log rotation and retention control. This guide describes the logging configuration options and behavior.
The logging system supports:
- Separate logging levels for console and file output
- Daily log rotation at midnight with date-based filenames (YYYY-MM-DD)
- Configurable log retention period
- Automatic cleanup of old log files
Logging is configured in the global section of the configuration file:
{
"global": {
"logging": {
"file": "logs/hblink.log",
"console_level": "INFO",
"file_level": "DEBUG",
"retention_days": 30,
"log_protocol": false,
"log_dmr_data": false,
"log_status_updates": true
}
}
}| Option | Type | Description | Default |
|---|---|---|---|
file |
string | Path to log file | "logs/hblink.log" |
console_level |
string | Logging level for console output | "INFO" |
file_level |
string | Logging level for file output | "DEBUG" |
retention_days |
number | Days to retain log files | 30 |
log_protocol |
boolean | Log protocol messages | false |
log_dmr_data |
boolean | Log DMR data packets | false |
log_status_updates |
boolean | Log repeater status | true |
The following log levels are available, in order of increasing severity:
- DEBUG: Detailed information for debugging
- INFO: General operational messages
- WARNING: Warning messages for potential issues
- ERROR: Error messages for serious problems
- Main log file:
logs/hblink.log - Rotated logs:
logs/hblink.log.YYYY-MM-DD - Log rotation occurs daily at midnight
- Old logs are automatically cleaned up based on retention_days
2024-01-20 10:15:23 - INFO - HBlink4 server is running on 0.0.0.0:62031 (UDP)
2024-01-20 10:15:30 - INFO - Repeater 312100 (WA0EDA-1) login request from 192.168.1.100:62031
2024-01-20 10:15:30 - DEBUG - Processing login for repeater ID 312100 from 192.168.1.100:62031
2024-01-20 10:15:31 - INFO - Repeater 312100 (WA0EDA-1) authenticated successfully
2024-01-20 10:15:31 - INFO - Repeater 312100 (WA0EDA-1) configured successfully
The log rotation system:
- Creates a new log file at midnight
- Renames the old log with the date suffix
- Maintains logs for the configured retention period
- Automatically cleans up logs older than retention_days on startup
-
Log Levels
- Use INFO for normal operation
- Use DEBUG during troubleshooting
- Adjust console and file levels independently
-
Storage Management
- Set appropriate retention_days based on needs
- Monitor disk space usage
- Archive important logs before deletion
-
Troubleshooting
- Enable log_protocol for protocol issues
- Enable log_dmr_data for data issues
- Check logs in chronological order
-
Security
- Protect log files with appropriate permissions
- Regularly review logs for security events
- Archive security-relevant logs
Certain sections of code have been commented out with specific marker phrases to make them easy to find and re-enable when needed. Use these phrases when searching the codebase:
Purpose: High-frequency debug logging that generates massive amounts of output
Location: hblink4/hblink.py
When to enable: Only when troubleshooting specific packet-level issues
Search command: grep -n "Per-packet logging" hblink4/hblink.py
Commented sections:
- Command bytes logging (line ~719)
- Packet received logging (line ~740)
- Repeater validation state logging (line ~785)
- Repeater not found validation (line ~791)
- DMR data per-packet details (line ~1333)
Warning: Enabling these logs will generate hundreds of log entries per second during active transmission. Use only for targeted debugging and disable immediately after.
Purpose: Embedded Link Control extraction from voice frames
Location: hblink4/hblink.py
Status: Not currently working correctly, disabled pending fix
Search command: grep -n "LC recovery" hblink4/hblink.py
Commented sections:
- StreamInfo fields:
missed_header,embedded_lc_bits(line ~78-79) - Function:
extract_embedded_lc()(line ~218) - Function:
decode_embedded_lc()(line ~285) - Embedded LC extraction in datagram handler (line ~1307)
Note: This feature was intended to recover Link Control information when the voice header frame is missed. The LC is still obtained from the DMRD packet header, so this is a backup/recovery mechanism only.
The logging system uses Python's built-in TimedRotatingFileHandler with these settings:
handler = TimedRotatingFileHandler(
log_file,
when='midnight',
interval=1,
backupCount=retention_days
)This ensures:
- Reliable daily rotation
- Clean timestamp-based naming
- Automatic cleanup of old files
- Thread-safe operation