{"id":18613899,"url":"https://github.com/enthought/graystruct","last_synced_at":"2025-11-03T02:30:38.830Z","repository":{"id":27985068,"uuid":"31478880","full_name":"enthought/graystruct","owner":"enthought","description":"Default Repo description from terraform module","archived":false,"fork":false,"pushed_at":"2019-09-12T10:53:55.000Z","size":244,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":22,"default_branch":"master","last_synced_at":"2025-02-17T16:05:53.740Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"afarhan/ubitx","license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/enthought.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}},"created_at":"2015-02-28T22:24:11.000Z","updated_at":"2021-06-01T16:22:06.000Z","dependencies_parsed_at":"2022-09-01T18:42:05.895Z","dependency_job_id":null,"html_url":"https://github.com/enthought/graystruct","commit_stats":null,"previous_names":["sjagoe/graystruct"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enthought%2Fgraystruct","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enthought%2Fgraystruct/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enthought%2Fgraystruct/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enthought%2Fgraystruct/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/enthought","download_url":"https://codeload.github.com/enthought/graystruct/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239321395,"owners_count":19619697,"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-07T03:24:10.437Z","updated_at":"2025-11-03T02:30:38.785Z","avatar_url":"https://github.com/enthought.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"============\n graystruct\n============\n\nIntegration between structlog and graylog GELF, provided by graypy.\n\n\nRationale\n=========\n\nStructlog_ provides a rich tool for producing structured log messages\nfrom applications.  Graypy_ provides a Python interface to emit logs in\nthe GELF_ format accepted by graylog_.  In effect, structlog_\npre-processes the _inputs_ to Python ``logging`` module, while graypy_\nprocesses the outputs (``LogRecord`` instances), and neither expects the\nother to be present.\n\n``graystruct`` provides a small integration layer composed of two main\ncomponents that are used in conjunction with both structlog_ and\ngraypy_.  These components minimally alter the behaviour of structlog_\nand graypy_ at their interface points so that they are able to cooperate\nin producing structured logs.\n\n\nExample\n=======\n\n\n.. code-block:: python\n\n    \u003e\u003e\u003e import logging\n    \u003e\u003e\u003e import structlog\n    \u003e\u003e\u003e from graystruct.encoder import GELFEncoder\n    \u003e\u003e\u003e from graystruct.handler import GELFHandler\n    \u003e\u003e\u003e from graystruct.rabbitmq import GELFRabbitHandler\n    \u003e\u003e\u003e from graystruct.utils import add_app_context\n    \u003e\u003e\u003e structlog.configure(\n    ...     logger_factory=structlog.stdlib.LoggerFactory(),\n    ...     processors=[\n    ...         # Prevent exception formatting if logging is not configured\n    ...         structlog.stdlib.filter_by_level,\n    ...         # Add file, line, function information of where log occurred\n    ...         add_app_context,\n    ...         # Format positional args to log as in stdlib\n    ...         structlog.stdlib.PositionalArgumentsFormatter(),\n    ...         # Add a timestamp to log message\n    ...         structlog.processors.TimeStamper(fmt='iso', utc=True),\n    ...         # Dump stack if ``stack_info=True`` passed to log\n    ...         structlog.processors.StackInfoRenderer(),\n    ...         # Format exception info is ``exc_info`` passed to log\n    ...         structlog.processors.format_exc_info,\n    ...         # Encode the message in GELF format (this must be the final processor)\n    ...         GELFEncoder(),\n    ...     ],\n    ... )\n    \u003e\u003e\u003e std_logger = logging.getLogger()\n    \u003e\u003e\u003e std_logger.setLevel(logging.WARNING)\n    \u003e\u003e\u003e gelf_handler = GELFHandler('localhost', 12201)\n    \u003e\u003e\u003e std_logger.addHandler(gelf_handler)\n    \u003e\u003e\u003e rabbit_handler = GELFRabbitHandler(\n            'amqp://user:passwd@localhost/', exchange='log-exchange',\n            queue='log-queue')\n    \u003e\u003e\u003e std_logger.addHandler(rabbit_handler)\n    \u003e\u003e\u003e logger = structlog.get_logger('some.package')\n    # Will transmit a GELF-encoded message directly to a graylog server and to rabbitmq\n    \u003e\u003e\u003e logger.error('user.login', username='sjagoe')\n\n\nNotes on RabbitMQ handler\n-------------------------\n\nThe ``GELFRabbitHandler`` will declare the exchange that it is\nsubmitting messages to.  The consumer is expected to create a queue\nbinding to the exchange when receiving messages.  If the consumer does\nnot, at least one queue binding should be made by the RabbitMQ server\nadministrator in order for log messages to be delivered.\n\n\n.. _structlog: https://pypi.python.org/pypi/structlog\n.. _Structlog: https://pypi.python.org/pypi/structlog\n\n.. _graypy: https://pypi.python.org/pypi/graypy\n.. _Graypy: https://pypi.python.org/pypi/graypy\n\n.. _graylog: https://www.graylog.org\n.. _GELF: https://www.graylog.org/resources/gelf-2/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenthought%2Fgraystruct","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fenthought%2Fgraystruct","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenthought%2Fgraystruct/lists"}