{"id":19713366,"url":"https://github.com/ctsit/report_handler","last_synced_at":"2026-06-07T22:33:53.788Z","repository":{"id":174026891,"uuid":"650788394","full_name":"ctsit/report_handler","owner":"ctsit","description":null,"archived":false,"fork":false,"pushed_at":"2024-05-09T14:12:08.000Z","size":51,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-27T20:32:40.814Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ctsit.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"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}},"created_at":"2023-06-07T20:09:57.000Z","updated_at":"2023-06-09T18:39:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"ebbafc22-696b-46a4-ae0f-bf41d5449da6","html_url":"https://github.com/ctsit/report_handler","commit_stats":null,"previous_names":["ctsit/report_handler"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/ctsit/report_handler","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctsit%2Freport_handler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctsit%2Freport_handler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctsit%2Freport_handler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctsit%2Freport_handler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ctsit","download_url":"https://codeload.github.com/ctsit/report_handler/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctsit%2Freport_handler/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34041087,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-07T02:00:07.652Z","response_time":124,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-11-11T22:21:20.090Z","updated_at":"2026-06-07T22:33:53.773Z","avatar_url":"https://github.com/ctsit.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# report_handler\n\n## About the project\nThis project helps separate the database and report logging from [`python_db_logger`](https://github.com/ctsit/python_db_logger) which requires a valid sql connection in order to log and generate a report. `report_handler` also adds the flexibility to the logger to add any number of handlers in order to send logs to different streams.\n\n## Getting Started\n\nThere are two methods to install this package in your project,\n\n- Using `pyproject.toml`:\n  - Add `\"report_handler @ git+https://git@github.com:/ctsit/report_handler.git\"` in the `dependencies` section of the file.\n  - Run `pip3 install .` to install in the virtual environment.\n- Using `setup.py`:\n  - Add `\"report_handler @ git+https://git@github.com:/ctsit/report_handler.git\"` in the `install_requires` section of the file.\n  - Run `pip3 install .` to install in the virtual environment.\n\n## Using the logger\n\n### 1: Imports\n\nImport the python `logging` module and `report_handler` using\n\n```python\nimport logging\nfrom report_handler.report_handler import ReportHandler\n```\n\n### 2: Creating logger instance\n\nA root logger is created by the `logging` package and can be accessed anywhere accross the codebase using `logging.getLogger()`. Any changes to this affects logging accross the codebase.\n\nSet the configuration for the logger as\n\n```python\nlogging.basicConfig(\n    level=logging.DEBUG,\n    format=fmt,\n    filename=file_name\n)\n```\n\nThe parameter definitions are:\n\n- `level`: This is the logging level and denotes the severity of logs. Can take values as `logging.CRITICAL`, `logging.ERROR`, `logging.WARNING`, `logging.INFO`, `logging.DEBUG` or `logging.NOTSET`.\n\n  - The severity levels are as follows:\n\n    | Level    | Numeric value |\n    | -------- | ------------- |\n    | CRITICAL | 50            |\n    | ERROR    | 40            |\n    | WARNING  | 30            |\n    | INFO     | 20            |\n    | DEBUG    | 10            |\n    | NOTSET   | 0             |\n\n  - `format`: The format of the logs in the log file. An example format is\n    `'%(asctime)s  %(levelname)-9s  %(message)s'`\n  - `filename`: Log file path\n\n### 3: Adding the handler and logging\n\nThis step includes getting the root logger and initializing the `report_handler` object and the adding it to the logger. This configures the root logger to pass the logs to `report_handler` also.\n\n```python\nreport_handler = ReportHandler()\nlogger = logging.getLogger()\nlogger.addHandler(report_handler)\n```\n\nTo log, call the following functions as required by the logging level:\n\n```python\nlogging.debug(msg: str,extra: dict)\nlogging.warning(msg: str,extra: dict)\nlogging.info(msg: str,extra: dict)\nlogging.error(msg: str,extra: dict)\n```\n\nThe parameter definitions are:\n\n- `msg`: _Required._ The logging message.\n- `extra`: _Optional_. This contains the handler and data information. The signature should match exactly as:\n\n```python\n{\"report_handler\": {\n                    \"data\": {\n                        'uid': uniqueid,\n                        'reason': 'missing doi'\n                        },\n                    'sheet': 'pub_checks'\n                    }\n}\n```\n\n`\"report_handler\"` should have `\"data\"` and `\"sheet\"` as keys with the correspoding values.\n\nReport handler also supports adding data using an array of entries using the `add_data_to_sheet` function:\n\n```python\nreport_handler.add_data_to_sheet(\n  sheet = \"sheet_name\",\n  data = {\n    \"headers\": [\"id\", \"failed_pub_check\"],\n    \"rows\": [\n      [\"1\", \"yes\"],\n      [\"2\", \"no\"]\n    ]\n  }\n)\n```\n\nThe signature should match exactly as the example above\n\n### 4: Generate report\n\nAt the very end of the program, generate the log `.xls` file using:\n\n```python\nreport_handler.write_report(file_path=\"logs\")\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fctsit%2Freport_handler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fctsit%2Freport_handler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fctsit%2Freport_handler/lists"}