{"id":20331014,"url":"https://github.com/cans/python-jsonlogging","last_synced_at":"2025-10-06T12:23:24.635Z","repository":{"id":139898306,"uuid":"223805230","full_name":"cans/python-jsonlogging","owner":"cans","description":"A JSON log formatter (Yes, another one !)","archived":false,"fork":false,"pushed_at":"2019-11-25T07:36:31.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-14T15:24:20.537Z","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":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cans.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"COPYING","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":"2019-11-24T20:25:48.000Z","updated_at":"2019-11-25T07:36:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"afeebd6e-06be-43d8-98fd-f303f49729aa","html_url":"https://github.com/cans/python-jsonlogging","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cans%2Fpython-jsonlogging","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cans%2Fpython-jsonlogging/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cans%2Fpython-jsonlogging/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cans%2Fpython-jsonlogging/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cans","download_url":"https://codeload.github.com/cans/python-jsonlogging/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241845876,"owners_count":20029956,"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":[],"created_at":"2024-11-14T20:18:28.634Z","updated_at":"2025-10-06T12:23:19.581Z","avatar_url":"https://github.com/cans.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"==============================\nYet another JSON log formatter\n==============================\n\nA python module to emit log entries as serialized JSON objects.\n\nFeatures\n\"\"\"\"\"\"\"\"\n\n- the ability to rename standard LogRecord attributes in\n  the json output:\n\n  .. code-block:: Python\n     :emphasize-lines: 7\n\n      import logging\n      import jsonlogging\n      import sys\n\n      handler = logging.StreamHandler(sys.stdout)\n      handler.setFormatter(jsonlogging.Formatter('%(asctime)s - %(levelname)s - %(message)s',\n                                                 keymap={'asctime': 'timestamp'})\n      logger = logging.getLogger('some-logger')\n      logger.propagate = False\n      logger.addHandler(handler)\n      logger.setLevel(logging.DEBUG)\n\n      logger.debug('This is a detail')\n      logger.info('This is an information')\n      logger.warning('This is suspicious')\n      logger.error('This is a problem')\n\n- the ability to use the format style you prefer (prevent\n  format mismatches whether you want JSON, text, ...);\n- structured stack traces, not just a blob of text;\n- support for global extras, like an application name,\n  anything you would normally \"hardcode\" in the log format\n  string, e.g. ``'%(asctime)s - %(levelname)s - myapplication - $(message)s'``;\n- excellent test coverage;\n\n\nExample YAML configuration\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n\nBelow is an example of a configuration file you can use with this library.\nA configured below, JSON logs will be sent to the file ``/tmp/jsonlogging.log``\n\nNote that we use the same format for both log formatters. The JSON formatter\nsimply ignores the extraneous text between log record attribute names (here\n``asctime``, ``level`` \u0026 ``message``)\n\n.. code-block:: YAML\n\n   ---\n   logformat: \u0026logfmt\n     fmt: '%(asctime)s - %(level)s - %(message)s'\n   logging:  # Below is a standard Python logging config\n     version: 1\n     formatters:\n       json:\n         (): jsonlogging.Formatter\n         \u003c\u003c: *logfmt\n         keymap:\n           asctime: timestamp\n         trunc_path: true\n       console:\n         class: logging.Formatter\n         \u003c\u003c: *logfmt\n     handlers:\n       console:\n         class: logging.StreamHandler\n         stream: ext://sys.stdout\n         propagate: false\n       syslog:\n         class: logging.FileHandler\n         path: /tmp/jsonlogging.log\n         propagate: false\n    loggers:\n      myapplication:\n        level: INFO\n      verboselib:\n        level: ERROR\n    root:\n       level: DEBUG\n       handlers:\n       - console\n       - syslog\n\nNote the use of the ``()`` key, in the yaml file, to specify the\nformatter class to instanciate. You have to `use this syntax \u003cuser\u003e`_\nso the configuration function will pass arguments other than ``fmt``,\n``datefmt`` and ``style`` to the class constructor. If you use the\n``class`` key (see below), only those 3 arguments are passed.\n\n.. code-block::\n\n   ---\n   logging:  # Below is a standard Python logging config\n     version: 1\n     formatters:\n       json:\n         class: jsonlogging.Formatter\n         fmt: '%(message)s'\n         datefmt: '%Y%m%d %H%M%S.%f'\n         # These arguments will be ignored\n         keymap:\n           asctime: timestamp\n         trunc_path: true\n\nTo use the configuration file in your application, you can do as follows:\n\n.. code-block:: Python\n\n   def main(config_path):\n       with open(config_path, 'r') as config_file:\n           config = yaml.safe_load(config_file)\n\n       logging.config.dictConfig(config['logging'])  # and your set !\n\n       logger = logging.getLogger('myapplication')\n       logger.debug('Should not appear')\n       logger.info('Should appear in your console and in /tmp/jsonlogging.log')\n\n\n.. _user: https://docs.python.org/3/library/logging.config.html#user-defined-objects\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcans%2Fpython-jsonlogging","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcans%2Fpython-jsonlogging","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcans%2Fpython-jsonlogging/lists"}