#35357: Logger should be able to store extra arguments
-------------------------------------+-------------------------------------
Reporter: Alexander Nestorov | Owner: nobody
Type: New feature | Status: new
Component: Uncategorized | Version:
Severity: Normal | Resolution:
Keywords: logging, logger, | Triage Stage:
extra | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Alexander Nestorov:
Old 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.
New 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(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.
--
--
Ticket URL: <
https://code.djangoproject.com/ticket/35357#comment:1>