Adding option to log to a debug text channel
authorEd Page <eopage@byu.net>
Sat, 19 Jun 2010 18:15:32 +0000 (13:15 -0500)
committerEd Page <eopage@byu.net>
Sat, 19 Jun 2010 18:15:32 +0000 (13:15 -0500)
src/channel/debug_prompt.py
src/connection.py

index 545f952..065ea07 100644 (file)
@@ -32,6 +32,7 @@ class DebugPromptChannel(tp.ChannelTypeText, cmd.Cmd):
                self.__lastMessageTimestamp = datetime.datetime(1, 1, 1)
 
                self.__otherHandle = contactHandle
+               self._conn.add_logger(self)
 
        @misc_utils.log_exception(_moduleLogger)
        def Send(self, messageType, text):
@@ -60,6 +61,11 @@ class DebugPromptChannel(tp.ChannelTypeText, cmd.Cmd):
                _moduleLogger.debug("Closing debug")
                tp.ChannelTypeText.Close(self)
                self.remove_from_connection()
+               self._conn.remove_logger(self)
+
+       def log_message(self, component, message):
+               formattedMessage = "LOG: %s\n%s" % (component, message)
+               self._report_new_message(formattedMessage)
 
        def _report_new_message(self, message):
                currentReceivedId = self.__nextRecievedId
index 59ffa76..1ad2487 100644 (file)
@@ -85,6 +85,8 @@ class TheOneRingConnection(
 
        @misc_utils.log_exception(_moduleLogger)
        def __init__(self, manager, parameters):
+               self._loggers = []
+
                self.check_parameters(parameters)
                account = unicode(parameters['account'])
                encodedAccount = parameters['account'].encode('utf-8')
@@ -188,6 +190,16 @@ class TheOneRingConnection(
 
                return h
 
+       def log_to_user(self, component, message):
+               for logger in self._loggers:
+                       logger.log_message(component, message)
+
+       def add_logger(self, logger):
+               self._loggers.append(logger)
+
+       def remove_logger(self, logger):
+               self._loggers.remove(logger)
+
        @property
        def _channel_manager(self):
                return self.__channelManager