diff options
author | Marco Pesenti Gritti <marco@localhost.localdomain> | 2006-08-11 11:05:33 (GMT) |
---|---|---|
committer | Marco Pesenti Gritti <marco@localhost.localdomain> | 2006-08-11 11:05:33 (GMT) |
commit | 628271959c97c49b64ed16203a5d8a2d0202ede7 (patch) | |
tree | 33e1e34f6d619d6fa7cf1c47da67d587e13194e4 /sugar/logger.py | |
parent | cb47f17b31dde57823d46d974e983aa7fe7cad98 (diff) |
Refactor the console stuff
Diffstat (limited to 'sugar/logger.py')
-rw-r--r-- | sugar/logger.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/sugar/logger.py b/sugar/logger.py new file mode 100644 index 0000000..54cb15b --- /dev/null +++ b/sugar/logger.py @@ -0,0 +1,34 @@ +import logging + +import dbus +import gobject + +class Handler(logging.Handler): + def __init__(self, shell, console_id): + logging.Handler.__init__(self) + + self._console_id = console_id + self._shell = shell + self._messages = [] + + def _log(self): + for message in self._messages: + # FIXME use a single dbus call + self._shell.log(self._console_id, message) + return False + + def emit(self, record): + self._messages.append(record.msg) + if len(self._messages) == 1: + gobject.idle_add(self._log) + +def start(console_id, shell = None): + root_logger = logging.getLogger('') + root_logger.setLevel(logging.DEBUG) + + if shell == None: + bus = dbus.SessionBus() + proxy_obj = bus.get_object('com.redhat.Sugar.Shell', '/com/redhat/Sugar/Shell') + shell = dbus.Interface(proxy_obj, 'com.redhat.Sugar.Shell') + + root_logger.addHandler(Handler(shell, console_id)) |