{"id":17347425,"url":"https://github.com/pr0ps/bracelogger","last_synced_at":"2025-04-14T20:43:41.456Z","repository":{"id":37600674,"uuid":"412592311","full_name":"pR0Ps/bracelogger","owner":"pR0Ps","description":"A Python library that enables using the brace-style string formatting in log messages","archived":false,"fork":false,"pushed_at":"2025-01-23T06:45:01.000Z","size":14,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-09T01:52:59.946Z","etag":null,"topics":["logging","python"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/bracelogger/","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/pR0Ps.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2021-10-01T19:20:47.000Z","updated_at":"2025-01-23T06:44:31.000Z","dependencies_parsed_at":"2024-02-02T04:50:33.464Z","dependency_job_id":null,"html_url":"https://github.com/pR0Ps/bracelogger","commit_stats":{"total_commits":6,"total_committers":1,"mean_commits":6.0,"dds":0.0,"last_synced_commit":"e5ada4eba6bcc6f69ab09f8834c7e6558aec1dba"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pR0Ps%2Fbracelogger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pR0Ps%2Fbracelogger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pR0Ps%2Fbracelogger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pR0Ps%2Fbracelogger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pR0Ps","download_url":"https://codeload.github.com/pR0Ps/bracelogger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248960158,"owners_count":21189979,"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","python"],"created_at":"2024-10-15T16:48:44.152Z","updated_at":"2025-04-14T20:43:41.429Z","avatar_url":"https://github.com/pR0Ps.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"bracelogger\n===========\n[![Status](https://github.com/pR0Ps/bracelogger/workflows/tests/badge.svg)](https://github.com/pR0Ps/bracelogger/actions/workflows/tests.yml)\n[![Version](https://img.shields.io/pypi/v/bracelogger.svg)](https://pypi.org/project/bracelogger/)\n![Python](https://img.shields.io/pypi/pyversions/bracelogger.svg)\n\nA Python library that enables using the brace-style string formatting in log messages.\n\nFeatures:\n - Supports a wide range of Python versions (v2.7 - v3.13)\n - No dependencies\n - Easy to use - no special syntax required\n - Easy to transition to from stdlib logging - just change the `logging.getLogger` calls and message\n   templates.\n - Only enables brace-style formatting for loggers created by the library. This allows for gradually\n   transitioning to brace-style formatting without breaking existing loggers or third party\n   packages.\n - The formatting of the message is delayed until it is output (or not at all if the log message is\n   filtered).\n - The args passed into the log call are stored on the `logging.LogRecord` objects as usual.\n\nInstallation\n------------\n```\npip install bracelogger\n```\n\nUsage example\n-------------\n```python\n# import the library\nfrom bracelogger import get_logger\n\n# set up the logger\n__log__ = get_logger(__name__)\n\n# use brace-style formatting in log messages\ntry:\n    process(some_obj)\nexcept Exception:\n    __log__.warning(\n        \"Failed to process object '{0!r}' with name '{0.name}' and path '{0.path}'\",\n        some_obj,\n        exc_info=True\n    )\n```\n\nNote that the above example is very basic. The real power of this module comes from being able to\nuse the more advanced operations that the brace-style formatting can provide. See\n[the docs on the format string syntax](https://docs.python.org/library/string.html#format-string-syntax)\nfor more details.\n\n\nKey-based formatting\n--------------------\nThe logger from the standard library has a special case (introduced in [Python\n2.4](https://github.com/python/cpython/blob/2.4/Lib/logging/__init__.py#L214-L227)) where key-based\nformatting can be used when a single non-empty dictionary is passed into the log message like so:\n```python\n__log__.info(\"a:%(a)s, b:%(b)s\", {\"a\": 1, \"b\": 2})\n```\nThis is also supported when using brace-style formatting:\n```python\n# These both produce the same log message:\n__log__.info(\"a:{a}, b:{b}\", {\"a\": 1, \"b\": 2})\n__log__.info(\"a:{0[a]}, b:{0[b]}\", {\"a\": 1, \"b\": 2})\n```\n\n\nCompatibility with existing code and loggers\n--------------------------------------------\nThis library will only enable brace-style formatting for loggers created by this module's\n`get_logger()` function. Loggers created via the stdlib `logging.getLogger()` function will still\nuse the normal %-based formatting.\n\nThis opt-in style means that codebases can gradually transition to brace-style logging without\nhaving to convert everything over all at once. It also means that the logs from any third-party code\nlike libraries will continue to work as normal.\n\nIn addition to being compatible with existing code, it should also be compatible with most other\nstdlib-compatible logging packages and modifications. As when using the stdlib logger, the message\narguments are still stored on the log record and the message is only formatted when it is handled\n(and not at all if the message is filtered).\n\n\nConverting existing code\n------------------------\nBecause there is no special syntax required, migrating existing logs to brace-style formatting is\neasy:\n1. Change loggers created with `logging.getLogger(name)` to use `bracelogger.get_logger(name)`\n2. Change the log messages for the loggers to use brace-style formatting (ex: change `%s` to `{}`)\n\n\nTests\n-----\nThis package contains basic tests. To run them, install `pytest` (`pip install pytest`) and run\n`py.test` in the project directory.\n\n\nLicense\n-------\nLicensed under the [GNU LGPLv3](https://www.gnu.org/licenses/lgpl-3.0.html).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpr0ps%2Fbracelogger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpr0ps%2Fbracelogger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpr0ps%2Fbracelogger/lists"}