Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyslogHandler's record formatting during emit(..) not covered by try-except block #66965

Closed
Yoel mannequin opened this issue Oct 31, 2014 · 3 comments
Closed

SyslogHandler's record formatting during emit(..) not covered by try-except block #66965

Yoel mannequin opened this issue Oct 31, 2014 · 3 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@Yoel
Copy link
Mannequin

Yoel mannequin commented Oct 31, 2014

BPO 22776
Nosy @vsajip

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2014-11-01.20:01:15.301>
created_at = <Date 2014-10-31.18:13:10.758>
labels = ['type-bug', 'library']
title = "SyslogHandler's record formatting during emit(..) not covered by try-except block"
updated_at = <Date 2014-11-01.20:03:23.125>
user = 'https://bugs.python.org/Yoel'

bugs.python.org fields:

activity = <Date 2014-11-01.20:03:23.125>
actor = 'vinay.sajip'
assignee = 'none'
closed = True
closed_date = <Date 2014-11-01.20:01:15.301>
closer = 'python-dev'
components = ['Library (Lib)']
creation = <Date 2014-10-31.18:13:10.758>
creator = 'Yoel'
dependencies = []
files = []
hgrepos = []
issue_num = 22776
keywords = []
message_count = 3.0
messages = ['230364', '230458', '230459']
nosy_count = 3.0
nosy_names = ['vinay.sajip', 'python-dev', 'Yoel']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue22776'
versions = ['Python 2.7', 'Python 3.4', 'Python 3.5', 'Python 3.6']

@Yoel
Copy link
Mannequin Author

Yoel mannequin commented Oct 31, 2014

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)
<ipython-input-8-3d1c89a066c4> in <module>()
----> 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.

@Yoel Yoel mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Oct 31, 2014
@python-dev
Copy link
Mannequin

python-dev mannequin commented Nov 1, 2014

New changeset 54549f9b2ecc by Vinay Sajip in branch 'default':
Closes bpo-22776: Merged fix from 3.4.
https://hg.python.org/cpython/rev/54549f9b2ecc

@python-dev python-dev mannequin closed this as completed Nov 1, 2014
@vsajip
Copy link
Member

vsajip commented Nov 1, 2014

N.B. 2.7 and 3.4 also updated, but I accidentally left the issue no. out of the commit message. Relevant changesets are ea7b64406396 and f6a906541476.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant