{"id":21886368,"url":"https://github.com/afriemann/mdc","last_synced_at":"2025-04-15T08:42:03.039Z","repository":{"id":48300767,"uuid":"121800761","full_name":"AFriemann/mdc","owner":"AFriemann","description":"Mapped Diagnostic Context style logging for Python","archived":false,"fork":false,"pushed_at":"2024-02-08T12:49:01.000Z","size":41,"stargazers_count":9,"open_issues_count":2,"forks_count":8,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T05:47:11.691Z","etag":null,"topics":["logging","mdc","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AFriemann.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2018-02-16T21:06:46.000Z","updated_at":"2023-09-21T09:41:26.000Z","dependencies_parsed_at":"2024-11-28T10:45:34.861Z","dependency_job_id":null,"html_url":"https://github.com/AFriemann/mdc","commit_stats":{"total_commits":39,"total_committers":4,"mean_commits":9.75,"dds":0.3846153846153846,"last_synced_commit":"147c3de43f3da4afe56c9bbda3edb8d3c152e7ab"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AFriemann%2Fmdc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AFriemann%2Fmdc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AFriemann%2Fmdc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AFriemann%2Fmdc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AFriemann","download_url":"https://codeload.github.com/AFriemann/mdc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249038887,"owners_count":21202803,"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","mdc","python"],"created_at":"2024-11-28T10:35:09.179Z","updated_at":"2025-04-15T08:42:03.032Z","avatar_url":"https://github.com/AFriemann.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"MDC\n===\n\n.. image:: https://travis-ci.org/AFriemann/mdc.svg?branch=master\n    :target: https://travis-ci.org/AFriemann/mdc\n\nThis is thought to be an easy to use, import and go, library for Mapped Diagnostic Context style logging.\n\nLogs should include all necessary fields collected by the python logging library.\nHelper methods are provided to add context fields where required.\n\n**NOTE** `1.2.0`: recent changes will result in changed json output if using the `MDCHandler` class:\n\n.. code:: python\n\n  \u003e\u003e\u003e with MDC(foobar=\"baz\"):\n  ...   logging.warning(\"test\") \n  { \"message\": \"test\", \"foobar\": \"baz\" }\n\n\nthis is a temporary solution to avoid breaking existing APIs. Please excuse any issues this might cause. In the future output handling should be done on the client side to avoid any possible breakage. The MDCHandler class will eventually be removed.\n\nInstallation\n------------\n\nPyPi:\n\n.. code:: bash\n\n  $ pip install --user mdc\n\nFrom source:\n\n.. code:: bash\n\n  $ pip install --user .\n\nUsage\n-----\n\nAdd a handler to the root logger or set the base handler with *logging.basicConfig*:\n\n.. code:: python\n\n  \u003e\u003e\u003e import logging\n  \u003e\u003e\u003e from mdc import MDCHandler\n\n  \u003e\u003e\u003e # use the MDCHandler only\n  \u003e\u003e\u003e logging.basicConfig(level=logging.DEBUG, handlers=[MDCHandler()])\n\n  \u003e\u003e\u003e # the MDC contextmanager\n  \u003e\u003e\u003e with MDC(foo='bar'):\n  ...     logging.warning('foobar')\n  { ..., \"mdc\": { \"foo\": \"bar\" }, \"extra\": {}, ... }\n\n  \u003e\u003e\u003e # the with_mdc decorator\n  \u003e\u003e\u003e @with_mdc(test='123')\n  ... def foobar(ctx):\n  ...   logging.warning('some warning')\n\n  \u003e\u003e\u003e foobar()\n  { ..., \"mdc\": { \"test\": \"123\" }, \"extra\": {}, ... }\n\n  \u003e\u003e\u003e # logging with extra fields\n  \u003e\u003e\u003e logging.error('some error', extra=dict(foo='bar'))\n  { ..., \"mdc\": {}, \"extra\": { \"foo\": \"bar\" }, ... }\n\nBy default log messages will include the following fields:\n\n.. code:: json\n\n  {\n    \"message\": \"deleting context b8321b4f-19ff-4c98-b011-5a97178e7ad6\",\n    \"logger\": \"mdc\",\n    \"timestamp\": \"2018-03-07T21:39:12.010851\",\n    \"level\": \"DEBUG\",\n    \"mdc\": {\n      \"foo\": \"bar\",\n      \"index\": 76\n    },\n    \"extra\": {},\n    \"python\": {\n      \"module\": \"__init__\",\n      \"function\": \"MDC\",\n      \"path\": \"/home/user/git/mdc/mdc/__init__.py\",\n      \"file\": \"__init__.py\",\n      \"line\": 56,\n      \"process\": {\n        \"name\": \"MainProcess\",\n        \"id\": 31678\n      },\n      \"thread\": {\n        \"name\": \"MainThread\",\n        \"id\": 140433289192768\n      }\n    }\n  }\n\nRunning tests:\n\n.. code:: bash\n\n  $ tox\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fafriemann%2Fmdc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fafriemann%2Fmdc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fafriemann%2Fmdc/lists"}