Skip to main content

Hydra-Structlog

CI PyPI Python Versions Support on Ko-fi

An opinionated hydra plugin to configure logging with structlog.

Usage

Structlog is fully integrated in Hydra through a config group named structlog for hydra.job_logging.

  1. Install the plugin.

    uv add hydra-structlog
    
  2. Override the job logging with a default in your config.

    defaults:
      - override hydra/job_logging=structlog
    
  3. Hydra will now emit JSON logs (by default to structured.log) and print human readably logs to the console.

Customization

Structlog comes configured with opinionated defaults.

To adjust the processors, use the hydra defaults as outlined above and overwrite individual config entries afterwards. For example:

defaults:
  - override hydra/job_logging=structlog

# Change the storage location
hydra:
  job_logging:
    handlers:
      json:
        filename: ${hydra.runtime.cwd}/logs/structured.log

Defaults

The configuration runs structlog through the standard library logging. That has several advantages.

The use of structlog and logging, e.g. by third-party packages, are recorded and both exhibit structlog's bound contextvars.

The processor chain is conveniently exposed in the job_logging configuration and adjustable through hydra's config interface.

Because lists are not easily manipulated in hydra configs, the processor chains are defined as dictionaries. The name of each processor does not matter as long as its unique in the chain. The default processor chain can then be extended more comfortably.

To remove a processor set it to null. See example below.

Because structlog's ProcessorFormatter does not accept the processors as strings, the logging config contains _target_ instantiation.

defaults:
  - override hydra/job_logging=structlog

# Remove a processor from the default chain and add another one
hydra:
  job_logging:
    formatters:
      json:
        foreign_pre_chain:
          # Remove the add-log-level processor
          add_logger_name: null
          # Append a new processor
          arbitrary_name:
            # Follow hydra's instantiate syntax
            _target_: structlog.stdlib.add_log_level_number
            _partial_: true

Notes

Python 3.14 is currently not supported as hydra.main causes a ValueError on argparse-validation, see https://github.com/facebookresearch/hydra/issues/3121. It is recommended to use hydra-zen which does not have that problem and works well with Python 3.14.

Tracer injection is not implemented here as data science projects using hydra typically do not implement web apps. Nevertheless, an appropriate structlog processor can be added to the job_logging config.

Metadata

Release files for hydra-structlog 1.0.2

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

Source distribution (sdist)

Source distribution for hydra-structlog 1.0.2
File Size Uploaded
hydra_structlog-1.0.2.tar.gz 8.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hydra-structlog 1.0.2
File Interpreter ABI Platform
hydra_structlog-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 19.8 kB

Release files / hydra_structlog-1.0.2.tar.gz

Download URL hydra_structlog-1.0.2.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
b3d940fe665ee61ff7b4b4c82a9e4aed31b97179e25d04e776b71bd0cba01449
BLAKE2b-256 checksum
How to use checksums
7a40cd7f33706ce8493e72eab2f8afc9ccf88c709b97ab5d23f60423cb81f749
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 8, 2026.

Transparency log

Release files / hydra_structlog-1.0.2-py3-none-any.whl

Download URL hydra_structlog-1.0.2-py3-none-any.whl
Size 11.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
de9b549fab28d97e74b9363ec6c3e62f442c4ce8fe5017ca5ca39c0917cea1d2
BLAKE2b-256 checksum
How to use checksums
fb3c0e9844c4264ebe4d427ab06733f660af89a42172c3d20d885fad6c5623b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 8, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

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