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.4

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.4
File Size Uploaded Provenance Actions
hydra_structlog-1.0.4.tar.gz 9.6 kB With provenance Details for hydra_structlog-1.0.4.tar.gz

Built distribution (wheel)

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

Total release size: 21.3 kB

Release files / hydra_structlog-1.0.4.tar.gz

Download URL hydra_structlog-1.0.4.tar.gz
Size 9.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ba6493ae44c910490bbaf334d49cfc85c96a02d4de0bda8b75346c2451f10e94
BLAKE2b-256 checksum
How to use checksums
1cd63688817280a4e033be9c630d81ef747b85769368cfdb5c445a9a23d39652
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Oct 27, 2026.

Transparency log

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

Download URL hydra_structlog-1.0.4-py3-none-any.whl
Size 11.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bbd326f4d2e1689efc8e90f5cafda567bba71380696ae56d07a18f4fca56a5a3
BLAKE2b-256 checksum
How to use checksums
4adce9f4a5388630910ad2f319bf920c1fb745dcef07ba9b15e32042b5bec04f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Oct 27, 2026.

Transparency log

Security for hydra-structlog 1.0.4

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for hydra_structlog-1.0.4.tar.gz

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 Oct 27, 2026.

Transparency log

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.

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