Logging Configuration
RouteMQ now supports comprehensive file logging with configurable rotation options. This document explains all available logging configuration options.
Overview
The logging system supports both console and file output with flexible rotation strategies based on file size or time intervals.
Environment Variables
Basic Logging Configuration
LOG_TO_FILE
true
Enable/disable file logging (true/false)
LOG_LEVEL
INFO
Log level: DEBUG, INFO, WARNING, ERROR, CRITICAL
LOG_FILE
logs/app.log
Log file path (relative to project root or absolute)
LOG_FORMAT
%(asctime)s - %(name)s - %(levelname)s - %(message)s
Log message format
Rotation Configuration
LOG_ROTATION_TYPE
size
Rotation strategy: 'size' or 'time'
Size-based Rotation (LOG_ROTATION_TYPE=size)
LOG_MAX_BYTES
10485760
Maximum file size in bytes before rotation (10MB)
LOG_BACKUP_COUNT
5
Number of backup files to keep
Time-based Rotation (LOG_ROTATION_TYPE=time)
LOG_ROTATION_WHEN
midnight
When to rotate: 'midnight', 'D' (daily), 'H' (hourly), 'W0-W6' (weekly), 'M' (monthly)
LOG_ROTATION_INTERVAL
1
Rotation interval (e.g., 1 for every day if WHEN=D)
LOG_DATE_FORMAT
%Y-%m-%d
Date format for backup file names
Configuration Examples
Example 1: Size-based Rotation (Default)
LOG_TO_FILE=true
LOG_FILE=logs/app.log
LOG_ROTATION_TYPE=size
LOG_MAX_BYTES=5242880 # 5MB
LOG_BACKUP_COUNT=3This creates:
logs/app.log(current log)logs/app.log.1(most recent backup)logs/app.log.2logs/app.log.3(oldest backup)
Example 2: Daily Time-based Rotation
LOG_TO_FILE=true
LOG_FILE=logs/app.log
LOG_ROTATION_TYPE=time
LOG_ROTATION_WHEN=midnight
LOG_ROTATION_INTERVAL=1
LOG_BACKUP_COUNT=7
LOG_DATE_FORMAT=%Y-%m-%dThis creates:
logs/app.log(current day)logs/app.log.2024-01-15(previous days)logs/app.log.2024-01-14etc.
Example 3: Hourly Rotation
LOG_TO_FILE=true
LOG_FILE=logs/hourly.log
LOG_ROTATION_TYPE=time
LOG_ROTATION_WHEN=H
LOG_ROTATION_INTERVAL=1
LOG_BACKUP_COUNT=24
LOG_DATE_FORMAT=%Y-%m-%d_%HExample 4: Weekly Rotation (Sunday)
LOG_TO_FILE=true
LOG_FILE=logs/weekly.log
LOG_ROTATION_TYPE=time
LOG_ROTATION_WHEN=W6 # Sunday (0=Monday, 6=Sunday)
LOG_ROTATION_INTERVAL=1
LOG_BACKUP_COUNT=4
LOG_DATE_FORMAT=%Y-W%UExample 5: Console Only (No File Logging)
LOG_TO_FILE=false
LOG_LEVEL=DEBUGLog Levels
DEBUG
Detailed information for debugging
INFO
General information messages
WARNING
Warning messages
ERROR
Error messages
CRITICAL
Critical error messages
Log Format Variables
The LOG_FORMAT variable supports Python logging format strings:
%(asctime)s
Timestamp
%(name)s
Logger name
%(levelname)s
Log level
%(message)s
Log message
%(filename)s
Source filename
%(lineno)d
Line number
%(funcName)s
Function name
%(process)d
Process ID
%(thread)d
Thread ID
File Path Configuration
Relative paths: Relative to the project root directory
logs/app.log→ Createslogs/directory in project roottemp/debug.log→ Createstemp/directory in project root
Absolute paths: Full system paths
/var/log/routemq/app.log(Linux/Mac)C:\logs\routemq\app.log(Windows)
Backup File Naming
Size-based Rotation
Current:
app.logBackups:
app.log.1,app.log.2, etc.
Time-based Rotation
Current:
app.logBackups:
app.log.YYYY-MM-DD,app.log.YYYY-MM-DD_HH, etc.
Error Handling
If file logging setup fails (e.g., permission issues, invalid path), the system:
Prints a warning to console
Falls back to console-only logging
Continues application startup normally
Performance Considerations
File I/O: File logging adds minimal overhead
Rotation: Automatic rotation prevents disk space issues
Backup Count: Higher backup counts use more disk space
Log Level: Lower levels (DEBUG) generate more log entries
Troubleshooting
Common Issues
Permission Denied
Ensure the application has write permissions to the log directory
Try using a different log file path
Directory Not Found
The system automatically creates parent directories
Check file path syntax for your operating system
Large Log Files
Reduce
LOG_MAX_BYTESfor more frequent rotationIncrease rotation frequency for time-based rotation
Lower the log level to reduce log volume
Missing Log Files
Check if
LOG_TO_FILE=trueVerify the log file path is correct
Check application startup messages for logging configuration
Last updated