[issue45465] logging messages are needlessly reformatted for every handler

2021-10-15 Thread Vinay Sajip


Vinay Sajip  added the comment:

Oh, I see what you mean now - I was thinking of the overall message formatted 
using a formatter. However, filters can still change a record's attributes and 
getMessage() could behave differently on different calls because of this. 
Changing things in this area could break existing code.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45465] logging messages are needlessly reformatted for every handler

2021-10-15 Thread Роман Донченко

Роман Донченко  added the comment:

But message formatting is controlled by the record, not by the handler. The 
same record will always be formatted the same way (assuming that getMessage is 
deterministic, which seems like a fair assumption).

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45465] logging messages are needlessly reformatted for every handler

2021-10-15 Thread Vinay Sajip


Vinay Sajip  added the comment:

A developer may wish to format messages differently for different audiences 
(i.e. different handlers) - for example, omit stack traces. This behaviour is 
by design.

--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45465] logging messages are needlessly reformatted for every handler

2021-10-14 Thread Ned Deily


Change by Ned Deily :


--
nosy: +vinay.sajip

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45465] logging messages are needlessly reformatted for every handler

2021-10-13 Thread Роман Донченко

New submission from Роман Донченко :

Consider this code:

```
import logging

class MyLogRecord(logging.LogRecord):
def getMessage(self):
print("Help! I am being formatted!")
return super().getMessage()

logging.setLogRecordFactory(MyLogRecord)

logger = logging.getLogger("test")
logger.addHandler(logging.StreamHandler())
logger.addHandler(logging.StreamHandler())

logger.error("%d", 123)
```

Its output is:

```
Help! I am being formatted!
123
Help! I am being formatted!
123
```

In other words, the record's `getMessage` method is called once for every 
handler. That seems quite unnecessary, especially since the formatted message 
is saved in the `message` field of the record by `Formatter.format`. 
`Formatter` could check whether the message has already been formatted, and if 
so, use the saved message.

--
components: Library (Lib)
messages: 403879
nosy: SpecLad
priority: normal
severity: normal
status: open
title: logging messages are needlessly reformatted for every handler
type: enhancement
versions: Python 3.10

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com