Skip to content

Implement (optional) structured logging #10

Description

@adamcharnock

I enquired with @hynek regarding how to implement this within a library. His abridged response:


There are basically two problems to be solved:

  1. How to configure? I think the user should configure structlog themselves and should be required to tell your lib explicitly that it wants to use structlog.
  2. How to log? Since structlog with its k/v support is a superset of logging and you want k/v logging this is not trivial. I think the best way would be to write a very thin shim that allows for log.info("event", x=y, a=b) and if structlog is not used, it’s will either format the k/v or transform it into logging-specific context information by passing it into logging.info("event", extra={"x": y, "a": b})?

Point 2 is mostly just a suggestion/request for comments, since nobody has done that publicly so far…


As an aside, the currently logging system does need a drastic overhaul. It is a bit rickety and it's saving grace is simply that it hasn't needed any modification in a long time. (See #16)

Any new logging system should avoid string interpolation, thereby allowing us to re-enable the logging-fstring-interpolation / logging-format-interpolation pylint checks

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions