Skip to content

How to lazy-log extras / lazy-evaluate interpolations #21

@black-snow

Description

@black-snow

With classic logging you'd:

logger.debug("some var: %s", the_var)

so that a perhaps costly conversion or interpolation isn't payed if the log level isn't debug or trace.
How would we do the same with structured logging?

logger.debug("some var: %s", the_var, extras={})

could work for the message but what if I need it inside another field?

logger.debug({"key1": "%s", "key2": "%s"}, var1, var2)

This looks nasty.

Or is there already something in place I've missed?

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationuser supportSomeone needs help with using the library

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions