MQTT Gateway uses a custom daily rotating file logger that captures errors and critical events during operation.
Log directory configuration
The log directory is configured via the LOG_DIR environment variable:
The default value is ./log if not specified (src/config.py:44).
The log directory is automatically created if it doesn’t exist when the logger is initialized (src/logging_setup.py:14).
Log file rotation
Log files are created daily with the naming pattern YYYY-MM-DD.log. The DailyFileHandler automatically:
- Creates a new log file each day based on the current date
- Writes to the current day’s file in append mode
- Closes the previous day’s file when the date changes
- Thread-safe file operations using locks (src/logging_setup.py:7-35)
Example log files:
The logger is configured to capture ERROR level and above only (src/logging_setup.py:40):
Log entries follow this format:
Example:
What gets logged
Startup errors
Fatal errors during application startup are logged before the process exits (src/main.py:27):
MQTT connection failures
When the MQTT client fails to connect to the broker (src/mqtt_client.py:67):
Invalid message payloads
When a message payload cannot be decoded or is not valid JSON (src/mqtt_client.py:81):
Flow processing errors
Errors during message processing for a specific flow (src/mqtt_client.py:101):
HTTP endpoint failures
When POST_ENDPOINT action fails to deliver the payload (src/processor.py:124-129):
Flow reload errors
Errors that occur when periodically reloading flows from the database (src/mqtt_client.py:122):
Docker logging
When running in Docker, mount the log directory as a volume to persist logs:
Logs are only written to files, not to stdout/stderr. Ensure the log directory is accessible and has write permissions.