New submission from the mulhern: Here's my illustrating trace:
Python 3.3.2 (default, Aug 23 2013, 19:00:04) [GCC 4.8.1 20130603 (Red Hat 4.8.1-1)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> class Junk(): ... def __repr__(self): ... raise AttributeError("junk") ... >>> import logging >>> logging.warning("%r", Junk()) Traceback (most recent call last): File "/usr/lib64/python3.3/logging/__init__.py", line 937, in emit msg = self.format(record) File "/usr/lib64/python3.3/logging/__init__.py", line 808, in format return fmt.format(record) File "/usr/lib64/python3.3/logging/__init__.py", line 546, in format record.message = record.getMessage() File "/usr/lib64/python3.3/logging/__init__.py", line 311, in getMessage msg = msg % self.args File "<stdin>", line 3, in __repr__ AttributeError: junk Logged from file <stdin>, line 1 The alternative that would be desirable is that the LogRecord initializer would catch the exception and log that something bad happened while trying to log. I expect that it would be better if it were optional behavior. Note that the use of the % operator happens very early in the logging process, so implementing your own handler or overriding the makeRecord method won't fix this problem. There are plenty of situations where you would like to log a lot of information, but would be embarrassed to crash while logging. I realize that I could implement this by surrounding every log call with some function that caught the exception and then logged that an exception had occurred while trying to log, but I think it might work better within the logging module. ---------- components: Library (Lib) messages: 213465 nosy: the.mulhern priority: normal severity: normal status: open title: LogRecord.__init__ should handle exception if % operation fails type: enhancement versions: Python 2.7, Python 3.1, Python 3.2, Python 3.3 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue20918> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com