Skip to content

FilteringBoundLogger exception() method has different API  #530

@alexcouper

Description

@alexcouper

FilteringBoundLogger exception call fails with positional arguments.

Example

import structlog
from structlog import get_logger
from structlog.stdlib import LoggerFactory

structlog.configure(logger_factory=LoggerFactory())
log = get_logger("test")
log.error("%s %s %s", "bob", "alice", "fred")
log.exception("%s %s %s", "bob", "alice", "fred")

Expected output:

2023-07-15 11:30:42 [error    ] bob alice fred
2023-07-15 11:30:42 [error    ] bob alice fred

Actual output:

2023-07-15 11:30:42 [error    ] bob alice fred
Traceback (most recent call last):
  File "/Users/alex/Work/syndis/aftra/debug/2023-07-13-logging.py", line 30, in <module>
    log.exception("%s %s %s", "bob", "alice", "fred")
TypeError: exception() takes 2 positional arguments but 5 were given

Some historical digging

b71aabb#diff-b87fe76f9eed7fd535af19eade4ac979499ddaaaba4611af36cc59f4b7f247fc introduced the exception method without the *args part of the signature.

That implementation was also later used for the exception method used by FilteringBoundLogger here

A later fix was made to exception to "add pos arg support to exception" here

But no corresponding fix was made to the functions found in _log_levels.py.

Question

Any reason I shouldn't provide a fix, that adjusts the _log_levels.py arguments to include *args and pass them through to the error call?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions