[Django] #35357: Logger should be able to store extra arguments

6 views
Skip to first unread message

Django

unread,
Apr 6, 2024, 5:30:23 AM4/6/24
to django-...@googlegroups.com
#35357: Logger should be able to store extra arguments
-------------------------------------+-------------------------------------
Reporter: Alexander | Owner: nobody
Nestorov |
Type: New | Status: new
feature |
Component: | Version:
Uncategorized | Keywords: logging, logger,
Severity: Normal | extra
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/35357>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 6, 2024, 5:34:31 AM4/6/24
to django-...@googlegroups.com
#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>

Django

unread,
Apr 6, 2024, 9:01:31 AM4/6/24
to django-...@googlegroups.com
#35357: Logger should be able to store extra arguments
-------------------------------------+-------------------------------------
Reporter: Alexander Nestorov | Owner: nobody
Type: New feature | Status: closed
Component: Utilities | Version:
Severity: Normal | Resolution: wontfix
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
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* component: Uncategorized => Utilities
* resolution: => wontfix
* status: new => closed

Comment:

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.
--
Ticket URL: <https://code.djangoproject.com/ticket/35357#comment:2>
Reply all
Reply to author
Forward
0 new messages