{"id":19082238,"url":"https://github.com/waikato-datamining/wai-logging","last_synced_at":"2026-06-30T01:01:15.411Z","repository":{"id":209946087,"uuid":"725324399","full_name":"waikato-datamining/wai-logging","owner":"waikato-datamining","description":"Simple helper library for logging.","archived":false,"fork":false,"pushed_at":"2025-08-24T23:37:51.000Z","size":22,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2026-02-17T06:33:18.833Z","etag":null,"topics":["logging","python3"],"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/waikato-datamining.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.rst","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":"2023-11-29T22:49:56.000Z","updated_at":"2025-08-24T23:36:50.000Z","dependencies_parsed_at":"2023-11-30T00:24:21.403Z","dependency_job_id":null,"html_url":"https://github.com/waikato-datamining/wai-logging","commit_stats":null,"previous_names":["waikato-datamining/wai-logging"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/waikato-datamining/wai-logging","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waikato-datamining%2Fwai-logging","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waikato-datamining%2Fwai-logging/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waikato-datamining%2Fwai-logging/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waikato-datamining%2Fwai-logging/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/waikato-datamining","download_url":"https://codeload.github.com/waikato-datamining/wai-logging/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waikato-datamining%2Fwai-logging/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34948227,"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-29T02:00:05.398Z","response_time":58,"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":["logging","python3"],"created_at":"2024-11-09T02:42:39.802Z","updated_at":"2026-06-30T01:01:15.405Z","avatar_url":"https://github.com/waikato-datamining.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# wai-logging\nSimple helper library for logging.\n\n\n## Installation\n\nFrom PyPI:\n\n```bash\npip install wai_logging\n```\n\nFrom Github:\n\n```bash\npip install git+https://github.com/waikato-datamining/wai-logging.git\n```\n\n\n## Methods\n\nThe following helper methods are available:\n\n* `init_logging` - initializes the logging with a default level, which can be overridden with an environment variable\n* `set_logging_level` - sets the logging level of a `logging.Logger` instance\n* `str_to_logging_level` - turns a string logging level into a `logging` module one, used by `init_logging` and `set_logging_level`\n* `add_logging_level` - adds an option for the logging level to an `argparse.ArgumentParser` instance\n* `add_logger_name` - adds an option for a custom name for a logger to an `argparse.ArgumentParser` instance\n\n\n## Usage\n\nBelow are some examples on how to use the aforementioned methods and what the \noutput may look like. \n\n### Example 1\n\nThe following logging setup only outputs on stderr using a simple format without timestamps: \n\n```python\nfrom wai.logging import init_logging, LOGGING_INFO, set_logging_level\nimport logging\n\ninit_logging(LOGGING_INFO)\nlogger = logging.getLogger(\"my.test\")\nset_logging_level(logger, LOGGING_INFO)\nlogger.debug(\"debugging output\")\nlogger.info(\"info output\")\nlogger.warning(\"warning output\")\n```\n\nThe output:\n\n```\nINFO:my.test:info output\nWARNING:my.test:warning output\n```\n\n### Example 2\n\nThis configuration uses timestamps in its output (`log_format`; see [format strings](https://docs.python.org/3/library/logging.html#logrecord-attributes)) \nand logs to a file as well (`filename`):\n\n```python\nfrom wai.logging import init_logging, LOGGING_INFO, set_logging_level, TIMESTAMP_LOG_FORMAT\nimport logging\n\ninit_logging(LOGGING_INFO, filename=\"./out.log\", log_format=TIMESTAMP_LOG_FORMAT)\nlogger = logging.getLogger(\"my.test\")\nset_logging_level(logger, LOGGING_INFO)\nlogger.debug(\"debugging output\")\nlogger.info(\"info output\")\nlogger.warning(\"warning output\")\n```\n\nThe output:\n\n```\n2025-01-14 09:25:22,837 - INFO - my.test - info output\n2025-01-14 09:25:22,837 - WARNING - my.test - warning output\n```\n\n### Example 3\n\nThe following setup uses a [rotating file handler](https://docs.python.org/3/library/logging.handlers.html#logging.handlers.RotatingFileHandler) \nand keeps a maximum of three backups (`backupCount`; log files get a numeric suffix like `.1`). \nA rotation is initiated when the process is restarted and the log file exceeds 100 bytes (`maxBytes`).\n\n```python\nfrom wai.logging import init_logging, LOGGING_INFO, set_logging_level\nimport logging.handlers\n\ninit_logging(LOGGING_INFO, handlers=[\n    logging.StreamHandler(), \n    logging.handlers.RotatingFileHandler(filename=\"./out.log\", backupCount=3, maxBytes=100)])\nlogger = logging.getLogger(\"my.test\")\nset_logging_level(logger, LOGGING_INFO)\nlogger.debug(\"debugging output\")\nlogger.info(\"info output\")\nlogger.warning(\"warning output\")\n```\n\nThe output:\n\n```\nINFO:my.test:info output\nWARNING:my.test:warning output\n```\n\n### Example 4\n\nThe following adds the logging level option to an `argparse` parser:\n\n```python\nimport argparse\nimport logging\nfrom wai.logging import init_logging, set_logging_level, add_logging_level\n\nlogger = logging.getLogger(\"tool-with-logging\")\ninit_logging()\nparser = argparse.ArgumentParser(\n    description=\"Tool with logging option.\",\n    prog=\"tool-with-logging\",\n    formatter_class=argparse.ArgumentDefaultsHelpFormatter)\nparser.add_argument(\"-i\", \"--input\", type=str, help=\"Input parameter\", required=False, nargs=\"+\")\nadd_logging_level(parser)\nparsed = parser.parse_args()\nset_logging_level(logger, parsed.logging_level)\nlogger.info(\"Input: %s\" % str(parsed.input))\n```\n\nThe above code, when executed with the `-l INFO` option, will output something \nlike this:\n\n```\nINFO:tool-with-logging:Input: None\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaikato-datamining%2Fwai-logging","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwaikato-datamining%2Fwai-logging","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaikato-datamining%2Fwai-logging/lists"}