Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/sugar/logger.py
blob: 54cb15b5807e2dfbf67672fdd9128ba20022ca0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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))