[Patches] [ python-Patches-1641790 ] logging leaks loggers

SourceForge.net noreply at sourceforge.net
Tue Jan 23 09:54:54 CET 2007


Patches item #1641790, was opened at 2007-01-22 17:00
Message generated for change (Comment added) made by therve
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1641790&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Library (Lib)
Group: Python 2.6
Status: Closed
Resolution: Invalid
Priority: 5
Private: No
Submitted By: TH (therve)
Assigned to: Vinay Sajip (vsajip)
Summary: logging leaks loggers

Initial Comment:
In our application, we used to create a logger per client (to get IP/port automatically in the prefix). Unfortunately logging leaks loggers by keeping it into an internal dict (attribute loggerDict of Manager).

Attached a patch using a weakref object, with a test.

----------------------------------------------------------------------

>Comment By: TH (therve)
Date: 2007-01-23 08:54

Message:
Logged In: YES 
user_id=1038797
Originator: YES

OK I understand the design. But it's not clear in the documentation that
once you've called getLogger('id') the logger will live forever. It's
especially problematic on long-running processes.

It would be great to have at least a warning in the documentation about
this feature.

----------------------------------------------------------------------

Comment By: Vinay Sajip (vsajip)
Date: 2007-01-23 08:42

Message:
Logged In: YES 
user_id=308438
Originator: NO

This is not a leak - it's by design. You are not using best practice when
you create a logger per client; the specific scenario of getting connection
info in the logging message can currently be done in several ways, e.g.

1. Use the 'extra' parameter (added in Python 2.5).
2. Use a connection-specific factory to obtain the logging message, or
wrap the logging call on a connection-specific object which inserts the
connection info.
3. Use something other than a literal string for the message - as
documented, any object can be used as the message, and the logging system
calls str() on it to get the actual text of the message. The "something"
can be an instance of a class which Does The Right Thing.

----------------------------------------------------------------------

Comment By: Neal Norwitz (nnorwitz)
Date: 2007-01-23 04:47

Message:
Logged In: YES 
user_id=33168
Originator: NO

Vinay, can you provide some direction?  Thanks.

----------------------------------------------------------------------

Comment By: TH (therve)
Date: 2007-01-22 17:09

Message:
Logged In: YES 
user_id=1038797
Originator: YES

Looking at the documentation, it seems keeping it is mandatory because you
must get the same instance with getLogger. Maybe it'd need a documented way
to remove from the dict, though.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1641790&group_id=5470


More information about the Patches mailing list