New submission from Роман Донченко <d...@corrigendum.ru>:
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 <rep...@bugs.python.org> <https://bugs.python.org/issue45465> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com