Logging in EthoPy¶
EthoPy provides a comprehensive logging system that handles both file and console output with configurable formats and levels. The logging system is centrally managed and provides consistent logging across all modules of the package.
Features¶
- Rotating file logs with size limits
- Colored console output
- Different formats for different log levels
- Centralized configuration
- Automatic log directory creation
- Multiple backup log files
Configuration¶
Default Settings¶
1 2 3 4 |
|
Local conf setting based on the local_conf.json¶
Logging is set up based on the parameters defined in the local_conf.json
1 2 3 4 5 |
|
Command Line Options¶
When running EthoPy from the command line, you can configure logging using these options:
1 2 3 4 |
|
Log Formats¶
File Logs¶
All file logs use the detailed format:
1 |
|
Example:
1 |
|
Console Logs¶
Console logs use two different formats based on the log level:
-
Simple Format (for INFO and DEBUG):
1
%(asctime)s - %(levelname)s - %(message)s
-
Detailed Format (for WARNING and above):
1
%(asctime)s - %(name)s - %(levelname)s - %(message)s (%(filename)s:%(lineno)d)
Color Coding¶
Console output is color-coded by log level:
- DEBUG: Grey
- INFO: Grey
- WARNING: Yellow
- ERROR: Red
- CRITICAL: Bold Red
Log File Management¶
Rotation¶
Log files are automatically rotated when they reach the maximum size:
- Maximum file size: 30 MB
- Number of backup files: 5
- Naming convention: ethopy.log, ethopy.log.1, ethopy.log.2, etc.
Directory Structure¶
1 2 3 4 5 |
|
Usage Examples¶
Basic Logging¶
1 2 3 4 5 6 7 8 |
|
Custom Logger¶
1 2 3 4 5 6 7 8 |
|
Best Practices¶
-
Log Level Selection - Use DEBUG for detailed debugging information - Use INFO for general operational messages - Use WARNING for unexpected but handled situations - Use ERROR for errors that affect functionality - Use CRITICAL for errors that require immediate attention
-
Message Content - Include relevant context in log messages - Be specific about what happened - Include important variable values - Avoid logging sensitive information
-
Performance Considerations - Avoid logging in tight loops - Use appropriate log levels to control output volume - Consider log rotation settings for long-running applications
Implementation Details¶
LoggingManager Class¶
The LoggingManager
class handles all logging configuration:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Custom Formatter¶
The logging system includes a custom formatter that provides:
- Color-coded output for different log levels
- Dynamic format selection based on log level
- Timestamp formatting
- File and line number information for warnings and errors
Troubleshooting¶
-
Missing Logs - Check write permissions for log directory - Verify log level configuration - Ensure log directory exists
-
Console Output Issues - Verify console logging is enabled - Check terminal color support - Confirm log level settings
-
Performance Issues - Review log rotation settings - Check logging frequency - Consider adjusting log levels