Message20461
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
|
|
Date |
User |
Action |
Args |
2007-08-23 14:20:52 | admin | link | issue932563 messages |
2007-08-23 14:20:52 | admin | create | |
|