classification
Title: logging.config.ConvertingDict issue with MemoryHandler
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.2, Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: vinay.sajip Nosy List: plemarre, python-dev, vinay.sajip
Priority: normal Keywords:

Created on 2013-03-21 12:34 by plemarre, last changed 2013-03-23 11:01 by python-dev. This issue is now closed.

Files
File name Uploaded Description Edit
bug-logging.py plemarre, 2013-03-21 12:34 Python script raising the error
Messages (5)
msg184866 - (view) Author: Pierre Le Marre (plemarre) Date: 2013-03-21 12:34
Hi, I use Python 3.2.3 and Python 3.3.0 on Windows 7 64 bits.
I have an issue with the short script enclosed.
I use the module logging to get a log file with logging.FileHandler. There were some issues about the file access on Windows, so I added a buffer with logging.handlers.MemoryHandler. I configure the logging using logging.config.dictConfig.
The issue appears when it comes to flush the MemoryHandler, either by reaching the capacity or by calling logging.shutdown(). Please find hereinbelow the traceback:

Traceback (most recent call last):
  File "C:\temp\bug-logging.py", line 38, in <module>
    logger.info(n)
  File "C:\Python32\lib\logging\__init__.py", line 1232, in info
    self._log(INFO, msg, args, **kwargs)
  File "C:\Python32\lib\logging\__init__.py", line 1364, in _log
    self.handle(record)
  File "C:\Python32\lib\logging\__init__.py", line 1374, in handle
    self.callHandlers(record)
  File "C:\Python32\lib\logging\__init__.py", line 1436, in callHandlers
    hdlr.handle(record)
  File "C:\Python32\lib\logging\__init__.py", line 835, in handle
    self.emit(record)
  File "C:\Python32\lib\logging\handlers.py", line 1090, in emit
    self.flush()
  File "C:\Python32\lib\logging\handlers.py", line 1150, in flush
    self.target.handle(record)
AttributeError: 'ConvertingDict' object has no attribute 'handle'
msg184930 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2013-03-22 00:42
Yes, this fails because it tries to construct the MemoryHandler first. Because the constructing is done in order of the keys, you can get it to work by renaming the 'fileGlobal' to 'afileGlobal' - this gets constructed before 'bufferGlobal'. I agree this is a workaround for now - I will implement a fix in due course.
msg184948 - (view) Author: Pierre Le Marre (plemarre) Date: 2013-03-22 07:47
Thank you for the tip! I just try it, it works. This behavior is not documented, so it is quite confusing.
I try also to use ``collections.OrderedDict``, as a quick fix, but it does not work. It seems we need here a simple resolution order.
msg184974 - (view) Author: Roundup Robot (python-dev) Date: 2013-03-22 15:28
New changeset 8ae1c28445f8 by Vinay Sajip in branch '2.7':
Issue #17508: Handled out-of-order handler configuration correctly.
http://hg.python.org/cpython/rev/8ae1c28445f8

New changeset ea00ae184d60 by Vinay Sajip in branch '3.2':
Issue #17508: Handled out-of-order handler configuration correctly.
http://hg.python.org/cpython/rev/ea00ae184d60

New changeset d674bbbed333 by Vinay Sajip in branch '3.3':
Issue #17508: Merged fix from 3.2.
http://hg.python.org/cpython/rev/d674bbbed333

New changeset b916efe30d77 by Vinay Sajip in branch 'default':
Closes #17508: Merged fix from 3.3.
http://hg.python.org/cpython/rev/b916efe30d77
msg185037 - (view) Author: Roundup Robot (python-dev) Date: 2013-03-23 11:01
New changeset 5f6747a0ffc4 by Vinay Sajip in branch '2.7':
Updated Misc/NEWS with #17508.
http://hg.python.org/cpython/rev/5f6747a0ffc4

New changeset 5f7185cae787 by Vinay Sajip in branch '3.2':
Updated Misc/NEWS with #17508.
http://hg.python.org/cpython/rev/5f7185cae787

New changeset bef32463ecd2 by Vinay Sajip in branch '3.3':
Merged Misc/NEWS update for #17508.
http://hg.python.org/cpython/rev/bef32463ecd2

New changeset 6dc72bd91de1 by Vinay Sajip in branch 'default':
Merged Misc/NEWS update for #17508.
http://hg.python.org/cpython/rev/6dc72bd91de1
History
Date User Action Args
2013-03-23 11:01:52python-devsetmessages: + msg185037
2013-03-22 15:28:18python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg184974

resolution: fixed
stage: resolved
2013-03-22 07:47:34plemarresetmessages: + msg184948
2013-03-22 00:42:41vinay.sajipsettype: crash -> behavior
2013-03-22 00:42:24vinay.sajipsetassignee: vinay.sajip
messages: + msg184930
2013-03-21 18:52:14r.david.murraysetnosy: + vinay.sajip
2013-03-21 12:34:27plemarrecreate