Opened 7 months ago

Closed 7 months ago

#35357 closed New feature (wontfix)

Logger should be able to store extra arguments

Reported by: Alexander Nestorov Owned by: nobody
Component: Utilities Version:
Severity: Normal Keywords: logging, logger, extra
Cc: Alexander Nestorov Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Alexander Nestorov)

I find myself quite often writing multiple logger.whatever() statements one after another just because I want to log multiple values.

logger.error("Foo failed. The bar object looked like")
logger.error(bar_object) # bar_object is a deep json-like object
logger.error(f"Retrying with {xyz} thing")

It would be nice if Django provided a way to log all values passed to extra, like this:

logger.error(f"Foo failed. The bar object looked like this. Retrying with {xyz} thing", extra={
    "bar_object": bar_object
})

I'm aware that I can create a custom logger inheriting from logging.Handler (or the several other ways this can be achieved), but IMHO this is such a basic feature that it should be included in Django itself.

Change History (2)

comment:1 by Alexander Nestorov, 7 months ago

Description: modified (diff)

comment:2 by Tim Graham, 7 months ago

Component: UncategorizedUtilities
Resolution: wontfix
Status: newclosed

While Django provides a few logging helpers, logger.error() is a Python APi. I doubt there would be consensus for Django to develop an alternative logging API as you've proposed (such code could likely be developed outside of Django). If you disagree, you can make your case on the DevelopersMailingList.

Note: See TracTickets for help on using tickets.
Back to Top