2006-05-23 22:02:13 +02:00
|
|
|
import os
|
|
|
|
import sys
|
2006-06-18 01:54:12 +02:00
|
|
|
import logging
|
|
|
|
|
2006-05-17 01:23:42 +02:00
|
|
|
import dbus
|
|
|
|
|
2006-06-18 01:54:12 +02:00
|
|
|
import sugar.env
|
|
|
|
|
2006-05-17 01:23:42 +02:00
|
|
|
class LogWriter:
|
2006-06-18 01:54:12 +02:00
|
|
|
def __init__(self, application, use_console = True):
|
2006-05-17 01:23:42 +02:00
|
|
|
self._application = application
|
2006-06-18 01:54:12 +02:00
|
|
|
self._use_console = use_console
|
|
|
|
|
2006-05-17 01:23:42 +02:00
|
|
|
bus = dbus.SessionBus()
|
|
|
|
proxy_obj = bus.get_object('com.redhat.Sugar.Logger', '/com/redhat/Sugar/Logger')
|
|
|
|
self._logger = dbus.Interface(proxy_obj, 'com.redhat.Sugar.Logger')
|
2006-06-18 01:54:12 +02:00
|
|
|
|
2006-05-23 22:02:13 +02:00
|
|
|
def start(self):
|
2006-06-20 05:04:53 +02:00
|
|
|
if self._use_console:
|
2006-05-23 22:02:13 +02:00
|
|
|
sys.stdout = self
|
|
|
|
sys.stderr = self
|
|
|
|
|
2006-06-18 01:54:12 +02:00
|
|
|
level = sugar.env.get_logging_level()
|
|
|
|
if level == 'debug':
|
|
|
|
logging.basicConfig(level=logging.DEBUG,
|
|
|
|
format='%(levelname)s %(message)s')
|
|
|
|
|
2006-05-17 01:23:42 +02:00
|
|
|
def write(self, s):
|
2006-06-14 21:27:54 +02:00
|
|
|
self._logger.log(self._application, s, ignore_reply=True)
|
2006-06-18 01:54:12 +02:00
|
|
|
|
|
|
|
def emit(self, record):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def flush(self):
|
|
|
|
pass
|