Opened 6 months ago

Last modified 6 months ago

#35357 closed New feature

Logger should be able to store extra arguments — at Initial Version

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

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("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 features that it should be included in Django itself.

Change History (0)

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