[ python-Bugs-932563 ] logging: need a way to discard Logger objects

SourceForge.net noreply at sourceforge.net
Wed Jun 9 05:28:27 EDT 2004


Bugs item #932563, was opened at 2004-04-09 21:51
Message generated for change (Comment added) made by vsajip
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=932563&group_id=5470

Category: Python Library
Group: Feature Request
Status: Open
Resolution: None
Priority: 5
Submitted By: Fred L. Drake, Jr. (fdrake)
Assigned to: Vinay Sajip (vsajip)
Summary: logging: need a way to discard Logger objects

Initial Comment:
There needs to be a way to tell the logging package
that an application is done with a particular logger
object.  This is important for long-running processes
that want to use a logger to represent a related set of
activities over a relatively short period of time
(compared to the life of the process).

This is useful to allow creating per-connection loggers
for internet servers, for example.  Using a
connection-specific logger allows the application to
provide an identifier for the session that can be
automatically included in the logs without having the
application encode it into each message (a far more
error prone approach).


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

>Comment By: Vinay Sajip (vsajip)
Date: 2004-06-09 09:28

Message:
Logged In: YES 
user_id=308438

Fred, any more thoughts on this? Thanks, Vinay

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

Comment By: Vinay Sajip (vsajip)
Date: 2004-05-08 19:28

Message:
Logged In: YES 
user_id=308438

The problem with disposing of Logger objects 
programmatically is that you don't know who is referencing 
them. How about the following approach? I'm making no 
assumptions about the actual connection classes used; if you 
need to make it even less error prone, you can create 
delegating methods in the server class which do the 
appropriate wrapping.

class ConnectionWrapper:
	def __init__(self, conn):
		self.conn = conn
		
	def message(self, msg):
		return "[connection: %s]: %s" % 
(self.conn, msg)
		
		
and then use this like so...

class Server:

	def get_connection(self, request):
		# return the connection for this request
		
	def handle_request(self, request):
		conn = self.get_connection(request)
		# we use a cache of connection wrappers
		if conn in self.conn_cache:
			cw = self.conn_cache[conn]
		else:
			cw = ConnectionWrapper(conn)
			self.conn_cache[conn] = cw
		#process request, and if events need to 
be logged, you can e.g.
		logger.debug(cw.message("Network packet 
truncated at %d bytes"), n)
		#The logged message will contain the 
connection ID


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

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



More information about the Python-bugs-list mailing list