How libranet/libranet-logging works
Main Components
• User Application Integration – a block representing the end–user’s code which calls libranet_logging.initialize() to set up logging.
• libranet_logging Library – the core of the project under the “src/libranet_logging” directory. This should be split logically into several internal modules:
– Config Loader & YAML Parser: Reads the logging.yml file (or a custom file set via the LOGGING_YML_FILE env–variable) and parses it.
– Configuration Validator: Validates the YAML file’s structure and values, ensuring required keys are present and values are correct.
– Environment Variables Manager: Reads env–variables like LOG_DIR, LOGLEVEL_ROOT, etc. to override or set default configurations.
– Logger & Handler Setup: Bridges the parsed configuration into the Python logging framework. This component creates and configures loggers, attaches handlers (console, file, email, syslog), and sets formatters and filters according to the YAML configuration.
• Python Logging Framework – is the underlying standard logging system which gets configured with loggers, handlers, filters, and formatters by this library.
• Additional Components (Optional/Future Enhancements): Blocks indicating email logger, syslog logger, and potential future JSON or Kibana integration.
Relationships and Data Flow
• That when the user application calls libranet_logging.initialize(), the process begins with:
• The Environment Variables Manager fetching configuration information.
• The Config Loader & YAML Parser reading the YAML configuration file.
• The Configuration Validator ensuring the integrity of the YAML.
• The Logger & Handler Setup applying the configuration to the Python Logging Framework.
• Finally, the user’s logging calls (log.debug, log.info, etc.) are processed by the now–configured Python logging system.
Architectural Patterns and Design Principles
• Separation of Concerns: Distinct modules handle configuration loading, validation, environment variable parsing, and logger setup.
• Config–Driven Behavior: Emphasize the use of external YAML configuration (and env variables) to minimize code changes.
• Extensibility: Note how the design allows for adding new logging handlers (such as email or syslog) without touching the core logic.
• Reusability: The library is designed to be imported and integrated into various applications without modifications.
Document Relevant Technologies and Tools
• Python Programming Language.
• YAML for configuration.
• Standard Python logging module.
• Testing frameworks (pytest, mypy, pre-commit, pylint, etc.) evident in the file tree.
• CI/CD configurations in GitHub workflows (linting.yaml, testing.yaml).