Skip to main content

graystruct

Integration between structlog and graylog GELF, provided by graypy.

Rationale

Structlog provides a rich tool for producing structured log messages from applications. Graypy provides a Python interface to emit logs in the GELF format accepted by graylog. In effect, structlog pre-processes the _inputs_ to Python logging module, while graypy processes the outputs (LogRecord instances), and neither expects the other to be present.

graystruct provides a small integration layer composed of two main components that are used in conjunction with both structlog and graypy. These components minimally alter the behaviour of structlog and graypy at their interface points so that they are able to cooperate in producing structured logs.

Example

>>> import logging
>>> import structlog
>>> from graystruct.encoder import GELFEncoder
>>> from graystruct.handler import GELFHandler
>>> from graystruct.utils import add_app_context
>>> structlog.configure(
...     logger_factory=structlog.stdlib.LoggerFactory(),
...     processors=[
...         # Prevent exception formatting if logging is not configured
...         structlog.stdlib.filter_by_level,
...         # Add file, line, function information of where log occurred
...         add_app_context,
...         # Format positional args to log as in stdlib
...         structlog.stdlib.PositionalArgumentsFormatter(),
...         # Add a timestamp to log message
...         structlog.processors.TimeStamper(fmt='iso', utc=True),
...         # Dump stack if ``stack_info=True`` passed to log
...         structlog.processors.StackInfoRenderer(),
...         # Format exception info is ``exc_info`` passed to log
...         structlog.processors.format_exc_info,
...         # Encode the message in GELF format (this must be the final processor)
...         structlog.processors.GELFEncoder(),
...     ],
... )
>>> std_logger = logging.getLogger()
>>> std_logger.setLevel(logging.WARNING)
>>> gelf_handler = GELFHandler('localhost', 12201)
>>> std_logger.addHandler(gelf_handler)
>>> logger = structlog.get_logger('some.package')
# Will transmit a GELF-encoded message
>>> logger.error('user.login', username='sjagoe')

Metadata

Release files for graystruct 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for graystruct 0.1.1
File Size Uploaded Provenance Actions
graystruct-0.1.1.zip 10.2 kB Without provenance Details for graystruct-0.1.1.zip

Release files / graystruct-0.1.1.zip

Download URL graystruct-0.1.1.zip
Size 10.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d76181886b0451e633d11e3023ebb4712d3452f944b13163661b775834569059
BLAKE2b-256 checksum
How to use checksums
0cb26d519b74d1f2e671bdaff707d4425763c9536692544c496a05c0e15fb785
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for graystruct 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

1 release file No provenance

0.0.1

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page