Introduction
The config_logging.json
file is an essential component of the G.O.D Framework that dictates
logging behavior across the system. It controls where logs are stored, their formatting, rotation schedules,
and the logging levels for debugging, info tracking, and error monitoring. This configuration is built in
JSON format to ensure compatibility with various libraries and platforms.
Purpose
The key objectives of config_logging.json
are:
- Centralizing logging configuration for all modules in the framework.
- Providing different log levels (e.g., DEBUG, INFO, WARNING, ERROR, CRITICAL) for monitoring and debugging.
- Enabling log rotation to manage disk usage effectively.
- Standardizing log formats for easier analysis and troubleshooting.
Structure
The configuration file is structured as a JSON object with nested fields. Below is a detailed example:
{
"version": 1,
"disable_existing_loggers": false,
"formatters": {
"detailed": {
"format": "%(asctime)s | %(name)s | %(levelname)s | %(message)s"
},
"simple": {
"format": "%(levelname)s | %(message)s"
}
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"level": "DEBUG",
"formatter": "simple",
"stream": "ext://sys.stdout"
},
"file": {
"class": "logging.handlers.RotatingFileHandler",
"level": "INFO",
"formatter": "detailed",
"filename": "/var/log/god_framework/app.log",
"maxBytes": 10485760,
"backupCount": 5,
"encoding": "utf8"
}
},
"loggers": {
"": {
"level": "INFO",
"handlers": ["console", "file"],
"propagate": true
}
}
}
This JSON configuration is divided into several key sections:
- formatters: Defines the structure and details included in log messages.
- handlers: Configures where logs are sent (e.g., console, file, external services) and how they are managed.
- loggers: Specifies which handlers to use and sets the global logging level.
Key Fields
- formatters:
- detailed: Logs with a timestamp, logger name, level, and message content.
- simple: Minimal logs showing only the severity level and message.
- handlers:
- console: Displays logs in the console for immediate debugging.
- file: Writes logs to a rotating file with a maximum size limit and backup file rotation.
- loggers: Defines the active logging setup, combining formatters and handlers with a specified log level.
- disable_existing_loggers: Whether to disable third-party loggers to avoid unwanted noise.
Integration with the G.O.D Framework
The config_logging.json
file integrates seamlessly across all modules in the framework:
- ai_error_tracker.py: Uses the logging configuration to capture and store error reports.
- ai_pipeline_audit_logger.py: Relies on the file handler to archive audit logs for long-term storage.
- ai_monitoring.py: Leverages the structured logs to provide monitoring insights in real time.
- main.py: Sets up the logging framework at the start of the application lifecycle.
Best Practices
- Keep log files rotated and limit their size to avoid excessive disk usage.
- Use the "DEBUG" log level only in development environments to avoid overwhelming log streams.
- Leverage "ERROR" and "CRITICAL" log levels for production environments to focus on key incidents.
- Always centralize logs for better monitoring (e.g., using ELK stack, Prometheus, or CloudWatch).
Future Enhancements
- Integrate support for external logging platforms like Datadog or Splunk.
- Enable dynamic reconfiguration of log levels without restarting the application.
- Extend the JSON configuration to include alerts for high severity levels (e.g., send emails for CRITICAL logs).
- Allow module-specific logging levels to isolate noisy or sensitive areas of the framework.