bug 200416: don't create a new logger for every channel and every sftp client or server. it causes python to leak lots of useless logger objects, because they never go away. instead, log the channel # in the message, and use only a couple of standard log nodes.
This commit is contained in:
parent
7854d600a7
commit
50d63690ee
|
@ -87,7 +87,7 @@ class Channel (object):
|
|||
self.in_window_sofar = 0
|
||||
self.status_event = threading.Event()
|
||||
self._name = str(chanid)
|
||||
self.logger = util.get_logger('paramiko.chan.' + str(chanid))
|
||||
self.logger = util.get_logger('paramiko.transport')
|
||||
self._pipe = None
|
||||
self.event = threading.Event()
|
||||
self.combine_stderr = False
|
||||
|
@ -394,14 +394,13 @@ class Channel (object):
|
|||
def set_name(self, name):
|
||||
"""
|
||||
Set a name for this channel. Currently it's only used to set the name
|
||||
of the log level used for debugging. The name can be fetched with the
|
||||
of the channel in logfile entries. The name can be fetched with the
|
||||
L{get_name} method.
|
||||
|
||||
@param name: new channel name.
|
||||
@param name: new channel name
|
||||
@type name: str
|
||||
"""
|
||||
self._name = name
|
||||
self.logger = util.get_logger(self.transport.get_log_channel() + '.' + self._name)
|
||||
|
||||
def get_name(self):
|
||||
"""
|
||||
|
@ -898,7 +897,7 @@ class Channel (object):
|
|||
|
||||
def _set_transport(self, transport):
|
||||
self.transport = transport
|
||||
self.logger = util.get_logger(self.transport.get_log_channel() + '.' + self._name)
|
||||
self.logger = util.get_logger(self.transport.get_log_channel())
|
||||
|
||||
def _set_window(self, window_size, max_packet_size):
|
||||
self.in_window_size = window_size
|
||||
|
@ -1062,7 +1061,7 @@ class Channel (object):
|
|||
|
||||
|
||||
def _log(self, level, msg, *args):
|
||||
self.logger.log(level, msg, *args)
|
||||
self.logger.log(level, "[chan " + self._name + "] " + msg, *args)
|
||||
|
||||
def _wait_for_event(self):
|
||||
while True:
|
||||
|
|
|
@ -129,10 +129,6 @@ class BaseSFTP (object):
|
|||
return version
|
||||
|
||||
def _log(self, level, msg):
|
||||
if issubclass(type(msg), list):
|
||||
for m in msg:
|
||||
self.logger.log(level, m)
|
||||
else:
|
||||
self.logger.log(level, msg)
|
||||
|
||||
def _write_all(self, out):
|
||||
|
|
|
@ -80,8 +80,7 @@ class SFTPClient (BaseSFTP):
|
|||
if type(sock) is Channel:
|
||||
# override default logger
|
||||
transport = self.sock.get_transport()
|
||||
self.logger = util.get_logger(transport.get_log_channel() + '.' +
|
||||
self.sock.get_name() + '.sftp')
|
||||
self.logger = util.get_logger(transport.get_log_channel() + '.sftp')
|
||||
self.ultra_debug = transport.get_hexdump()
|
||||
try:
|
||||
server_version = self._send_version()
|
||||
|
@ -106,6 +105,9 @@ class SFTPClient (BaseSFTP):
|
|||
return cls(chan)
|
||||
from_transport = classmethod(from_transport)
|
||||
|
||||
def _log(self, level, msg):
|
||||
super(SFTPClient, self)._log(level, "[chan " + self.sock.get_name() + "] " + msg)
|
||||
|
||||
def close(self):
|
||||
"""
|
||||
Close the SFTP session and its underlying channel.
|
||||
|
|
|
@ -66,8 +66,7 @@ class SFTPServer (BaseSFTP, SubsystemHandler):
|
|||
BaseSFTP.__init__(self)
|
||||
SubsystemHandler.__init__(self, channel, name, server)
|
||||
transport = channel.get_transport()
|
||||
self.logger = util.get_logger(transport.get_log_channel() + '.' +
|
||||
channel.get_name() + '.sftp')
|
||||
self.logger = util.get_logger(transport.get_log_channel() + '.sftp')
|
||||
self.ultra_debug = transport.get_hexdump()
|
||||
self.next_handle = 1
|
||||
# map of handle-string to SFTPHandle for files & folders:
|
||||
|
@ -75,6 +74,9 @@ class SFTPServer (BaseSFTP, SubsystemHandler):
|
|||
self.folder_table = { }
|
||||
self.server = sftp_si(server, *largs, **kwargs)
|
||||
|
||||
def _log(self, level, msg):
|
||||
super(SFTPServer, self)._log(level, "[chan " + self.sock.get_name() + "] " + msg)
|
||||
|
||||
def start_subsystem(self, name, transport, channel):
|
||||
self.sock = channel
|
||||
self._log(DEBUG, 'Started sftp server on channel %s' % repr(channel))
|
||||
|
|
Loading…
Reference in New Issue