Skip to content

Feature request: Implement a context manager to bind variables to a logger #2062

Closed
@wesleyhamburger-okta

Description

@wesleyhamburger-okta

Use case

I wan't to add variables to the logger for the duration of a request and get clean up for free without needing to explicitly call delete.

This is similar to https://www.structlog.org/en/stable/api.html#structlog.contextvars.bound_contextvars

Solution/User Experience

@contextmanager
def bind(self, **args):
    logger_instance.append_keys(**args)
    yield logger_instance
    logger_instance.remove_keys(args.keys())
with logger.bind(user_id=123):
    perform_operation():

Alternative solutions

No response

Acknowledgment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature-requestfeature requestneed-customer-feedbackRequires more customers feedback before making or revisiting a decisionneed-more-informationPending information to continue

    Type

    No type

    Projects

    Status

    Shipped

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions