Skip to main content

Library to enrich structured logs

Project description


CircleCI PyPI Downloads PyPI Version License

This is a log enricher, useful for adding custom fields to log records.

This was developed at GRID for use with our python backend services and intended to emit structured logs.


pip install log-enricher


The log-enricher takes in a list of functions that return a dictionary:

import os

from log_enricher import initialize_logging, Level
from app import current_user_context

def main():
    extra_log_properties = {
        "app_version": os.environ.get("APP_VERSION", "N/A"),
        "release_stage": os.environ.get("RELEASE_STAGE", "unknown"),
        loggers=["uvicorn", "sqlalchemy"],
        structured_logs=os.environ.get("STRUCTURED_LOGS", True),
        enrichers=[current_user_context, lambda: extra_log_properties],

Logs will be output in a structured JSON format if structured_logs is True, or in a plain, console-friendly format if it is False.


To build a log enricher, make a subclass of Enricher, or Callable, and implement __call__(). Any method returning a dict can be used to enrich log records. See log_enricher/ The key-value pairs in the dict are added as attribute-value pairs to the log record. Of course, any method calls in the enrichers need to work in any subsequent context the logging system is called.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

log-enricher-0.1.3.tar.gz (3.8 kB view hashes)

Uploaded source

Built Distribution

log_enricher-0.1.3-py3-none-any.whl (3.9 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page