logging as of 2022-02-01

Change-Id: I63c681bea9553cd822b214075b163ca6c42fe0cc
This commit is contained in:
2022-02-02 09:54:54 +01:00
parent 05d0cfb193
commit 9109170752
3 changed files with 193 additions and 13 deletions

View File

@ -130,6 +130,7 @@ class Dispatcher:
self._connections.remove(conn)
for _evt, conns in list(self._subscriptions.items()):
conns.discard(conn)
self.set_all_log_levels(conn, 'off')
self._active_connections.discard(conn)
def register_module(self, moduleobj, modulename, export=True):
@ -375,11 +376,33 @@ class Dispatcher:
# XXX: also check all entries in self._subscriptions?
return (DISABLEEVENTSREPLY, None, None)
def send_log_msg(self, conn, modname, level, msg):
"""send log message """
if conn in self._connections:
conn.send_reply(('log', '%s:%s' % (modname, level), msg))
return True
return False
def set_all_log_levels(self, conn, level):
for modobj in self._modules.values():
modobj.setRemoteLogging(conn, level)
def handle_logging(self, conn, specifier, level):
if specifier and specifier != '.':
modobj = self._modules[specifier]
iodev = getattr(modobj, '_iodev', None)
if iodev and iodev.remoteLogHandler is None:
iodev.setRemoteLogging(conn, 'off')
iodev.remoteLogHandler.used_by.add(modobj)
modobj.setRemoteLogging(conn, level)
else:
self.set_all_log_levels(conn, level)
return 'logging', specifier, level
def close(self):
for conn in self._connections:
try:
# - may be used for the 'closed' message in serial interface
# - is used in frappy history for indicating the close time
conn.close_message((ERRORCLOSED, None, None))
except AttributeError:
pass