[issue22776] SyslogHandler's record formatting during emit(..) not covered by try-except block

2014-10-31 Thread Yoel

New submission from Yoel:

Not all exceptions occurring during SyslogHandler's emit(..) method are caught 
and handled since the try-except block only covers the latter part of the 
method.
Thus, since handleError is not invoked, such exceptions might cause the whole 
program to crash, even though logging.raiseExceptions is unset.

Execution example:

In [1]: import sys

In [2]: sys.version
Out[2]: '2.7.6 (default, Mar 22 2014, 22:59:56) \n[GCC 4.8.2]'

In [3]: import logging.handlers

In [4]: logging.raiseExceptions = 0

In [5]: syslogHandler = logging.handlers.SysLogHandler()

In [6]: logger = logging.getLogger()

In [7]: logger.addHandler(syslogHandler)

In [8]: logger.critical('1', '1')
---
TypeError Traceback (most recent call last)
 in ()
> 1 logger.critical('1', '1')

/usr/lib/python2.7/logging/__init__.pyc in critical(self, msg, *args, **kwargs)
   1195 """
   1196 if self.isEnabledFor(CRITICAL):
-> 1197 self._log(CRITICAL, msg, args, **kwargs)
   1198 
   1199 fatal = critical

/usr/lib/python2.7/logging/__init__.pyc in _log(self, level, msg, args, 
exc_info, extra)
   1269 exc_info = sys.exc_info()
   1270 record = self.makeRecord(self.name, level, fn, lno, msg, args, 
exc_info, func, extra)
-> 1271 self.handle(record)
   1272 
   1273 def handle(self, record):

/usr/lib/python2.7/logging/__init__.pyc in handle(self, record)
   1279 """
   1280 if (not self.disabled) and self.filter(record):
-> 1281 self.callHandlers(record)
   1282 
   1283 def addHandler(self, hdlr):

/usr/lib/python2.7/logging/__init__.pyc in callHandlers(self, record)
   1319 found = found + 1
   1320 if record.levelno >= hdlr.level:
-> 1321 hdlr.handle(record)
   1322 if not c.propagate:
   1323 c = None#break out

/usr/lib/python2.7/logging/__init__.pyc in handle(self, record)
747 self.acquire()
748 try:
--> 749 self.emit(record)
750 finally:
751 self.release()

/usr/lib/python2.7/logging/handlers.pyc in emit(self, record)
840 exception information is present, it is NOT sent to the server.
841 """
--> 842 msg = self.format(record) + '\000'
843 """
844 We need to convert record level to lowercase, maybe this will

/usr/lib/python2.7/logging/__init__.pyc in format(self, record)
722 else:
723 fmt = _defaultFormatter
--> 724 return fmt.format(record)
725 
726 def emit(self, record):

/usr/lib/python2.7/logging/__init__.pyc in format(self, record)
462 it is formatted using formatException() and appended to the 
message.
463 """
--> 464 record.message = record.getMessage()
465 if self.usesTime():
466 record.asctime = self.formatTime(record, self.datefmt)

/usr/lib/python2.7/logging/__init__.pyc in getMessage(self)
326 msg = self.msg  #Defer encoding till later
327 if self.args:
--> 328 msg = msg % self.args
329 return msg
330 

TypeError: not all arguments converted during string formatting

In [9]: 

Executing similar code via StreamHandler for example, doesn't raise the 
TypeError exception.

--
components: Library (Lib)
messages: 230364
nosy: Yoel, vinay.sajip
priority: normal
severity: normal
status: open
title: SyslogHandler's record formatting during emit(..) not covered by 
try-except block
versions: Python 2.7, Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 3.6

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



[issue22776] SyslogHandler's record formatting during emit(..) not covered by try-except block

2014-10-31 Thread Yoel

Changes by Yoel :


--
type:  -> behavior

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