{"id":29016177,"url":"https://github.com/arnabd64/python-custom-logging","last_synced_at":"2025-06-25T22:07:06.796Z","repository":{"id":300174515,"uuid":"1005375792","full_name":"arnabd64/Python-Custom-Logging","owner":"arnabd64","description":"Custom Python logging modules that can integrate with the inbuilt python logging module.","archived":false,"fork":false,"pushed_at":"2025-06-20T07:43:29.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-20T08:38:22.150Z","etag":null,"topics":["logging","observability","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arnabd64.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-20T06:14:14.000Z","updated_at":"2025-06-20T07:45:27.000Z","dependencies_parsed_at":"2025-06-20T08:38:23.974Z","dependency_job_id":"64d61d14-cf23-4617-b7d9-0ee1019711e2","html_url":"https://github.com/arnabd64/Python-Custom-Logging","commit_stats":null,"previous_names":["arnabd64/python-custom-logging"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/arnabd64/Python-Custom-Logging","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnabd64%2FPython-Custom-Logging","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnabd64%2FPython-Custom-Logging/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnabd64%2FPython-Custom-Logging/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnabd64%2FPython-Custom-Logging/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arnabd64","download_url":"https://codeload.github.com/arnabd64/Python-Custom-Logging/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnabd64%2FPython-Custom-Logging/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261960463,"owners_count":23236574,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["logging","observability","python"],"created_at":"2025-06-25T22:07:04.980Z","updated_at":"2025-06-25T22:07:06.782Z","avatar_url":"https://github.com/arnabd64.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Python Custom Logger\n\n# Overview\n\nThis repository serves as a simple guide for the readers to build custom loggers for their python projects. Logging is a key feature that should be incorporated into applications which can help us to monitor our applications. There are several libraries and framework available for python which can help developers integrate logging but I prefer to use the inbuilt `logging` module because it reduces 3rd party package dependencies. Although sometimes when using the `logging` module, we may need to develop our custom logging logic to integrate with 3rd party services like SQL Databases or other logging servers.\n\n# Python Logging Pipeline\n\nLet's see an overview of Python's `logging` pipeline.\n\n1. First we create a new **LogRecord** while executing `logger.info`, `logger.debug` or `logger.error`.\n2. The `LogRecord` object is passed through an optional **Filter**. If the filter returns `True` then the `LogRecord` is forwarded in the pipeline else it is dropped.\n3. Next step is to transform the `LogRecord` into a suitable format using the **Formatter**.\n4. Finally the **Handler** dispatches or emits the formatted log to our desired location.\n\n# Examples\n\n## Basic Console Logging\n\nThe Console logs are the most simple form of logging that python by default provides to it's users. Everytime we log an event, we see the event in the terminal. The formatter converts the `LogRecord` instance into a plaintext string which the `StreamHandler` pushes to the terminal for the user to see.\n\n## Structured Logging to SQLite Database\n\nStructured logging is type of logging where the logs are **stored** in a predefined structure like JSON, XMLs, SQL Tables etc. Structured Logging has been to be useful for debugging applications in a production environment. \n\nFor this example we will be needed **SQLAlchemy** which is a popular ORM framework for Database operations. You can refer to [sqlite_logger](./custom_loggers/sqlite_logger.py) for more details. For this example we have to create a database model for storing logs.\n\nWe must define a custom formatter named `SQLAlchemyFormatter` which converts a `LogRecord` instance into an instance of the SQLAlchemy data model. Then the `SQLAlchemyHandler` pushes the record to the SQLite Database.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farnabd64%2Fpython-custom-logging","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farnabd64%2Fpython-custom-logging","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farnabd64%2Fpython-custom-logging/lists"}