How prakhar-luke-dev/my_logger works
Main Components
• Client Code: The consumer or client code that imports the library and calls the setup functions to obtain logger instances.
• Logger Setup Module (llogger.py): This is the main entry point for configuring loggers. It handles setting up file logging, JSON logging, and network logging (Logstash).
• JSON Formatter Module (jsonformatter.py): When JSON formatting is requested, this component formats the log messages following the provided scheme.
• Logstash Integration: Although implemented within the logger setup, this represents the pathway where logs are sent over the network to a Logstash endpoint.
• Future Extensions (Bugsnag Integration): Although not fully implemented, this is indicated for future enhancements, so consider it as a potential component that may wrap or extend logger functionality.
• Configuration & Packaging: The presence of configuration files (pyproject.toml, setup.cfg) indicates that the project prepares for packaging and distribution.
Depicting the Relationships and Interactions
• Within the Logger Setup module, include a decision branch:
• One branch connects to a “File Logging Handler” component when logging to files.
• Another branch, when JSON formatting is enabled, shows a connection from “Logger Setup” to the “JSON Formatter Module (jsonformatter.py)” before directing logs to a file or over the network.
• Additionally, include a branch to “Logstash Integration” when the client specifies logstash_host and logstash_port.
Architecture Patterns & Design Principles
• Separation of Concerns: The design clearly separates the logger configuration (llogger.py) from the message formatting (jsonformatter.py), which is critical for maintainability.
• Extensibility: The structure explicitly supports extensions (e.g., future Bugsnag integration) without major refactoring.
• Encapsulation: Client code interacts only with the public API (setup_logger and add_bugsnag_to_logger), abstracting the internal logging management.
Relevant Technologies and Frameworks
• Python, as the core language.
• Standard logging libraries (implicitly used or extended within this project).
• Integration with external systems like Logstash.
• Optional integration with a third-party error monitoring tool like Bugsnag.
• From “Logger Setup”, branch out:
• Optionally, add a branch from “Logger Setup” (or label next to it) for the “Logstash Integration.”
• Small annotations that indicate configuration elements like “log_handler”, “use_json”, “log_file”, and “logstash_host/port.”