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.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 hydra-structlog 1.0.1
File Size Uploaded
hydra_structlog-1.0.1.tar.gz 8.5 kB Details

Built distribution (wheel)

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

Total release size: 19.6 kB

Release files / hydra_structlog-1.0.1.tar.gz

Download URL hydra_structlog-1.0.1.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
01a9e612b6fdaf87925d6cb184b15f2c9a3216ea876521192030b248675c344b
BLAKE2b-256 checksum
How to use checksums
7e2761260678a0db28e31a20813f82b4d88ef40a6afb808ec29c338aac04732a
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 Aug 13, 2026.

Transparency log

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

Download URL hydra_structlog-1.0.1-py3-none-any.whl
Size 11.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8a2570e5bd3f37f5ba0b487b89bab6ac73d653c83d5f622cb6f8616510a117ae
BLAKE2b-256 checksum
How to use checksums
c135b4a9188dda45304d8ab66cb79e90b14a7f8b95cd12455867669d70c107a3
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 Aug 13, 2026.

Transparency log

Release history Release notifications | RSS feed

1.0.2

2 release files

This release

1.0.1 This release

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