summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLouis-Francis Ratté-Boulianne <louis-francis.ratte-boulianne@collabora.co.uk>2009-08-17 16:43:25 -0400
committerJonny Lamb <jonny.lamb@collabora.co.uk>2009-08-25 18:58:48 +0100
commitfad2d8daf0e0b029521bc95d513530716aff7cf9 (patch)
tree4c0b386017e9ff1244ded66d3ed2d9f1788a8f65 /src
parenta0f8d98cef6dc75ac84fc9f2b8cc7d4f4965d25d (diff)
Log messages written on stderr (debug interface)
Diffstat (limited to 'src')
-rw-r--r--src/server/debug.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/server/debug.py b/src/server/debug.py
index 78f738d..a12e28d 100644
--- a/src/server/debug.py
+++ b/src/server/debug.py
@@ -28,6 +28,8 @@ from telepathy.server.properties import DBusProperties
import dbus.service
import logging
+import sys
+import time
LEVELS = {
logging.ERROR: DEBUG_LEVEL_ERROR,
@@ -54,6 +56,7 @@ class Debug(_Debug, DBusProperties, logging.Handler):
self._implement_property_get(DEBUG, {'Enabled': lambda: self.enabled})
logging.getLogger(root).addHandler(self)
+ sys.stderr = StdErrWrapper(self, sys.stderr)
def GetMessages(self):
return self._messages
@@ -81,3 +84,30 @@ class Debug(_Debug, DBusProperties, logging.Handler):
domain, category = record.name.split('.', 1)
name = domain + "/" + category
return name
+
+# Wrapper around stderr so the exceptions are logged
+
+class StdErrWrapper(object):
+
+ def __init__(self, interface, stderr):
+ self._buffer = ""
+ self._interface = interface
+ self._stderr = stderr
+
+ def __getattr__(self, attr):
+ return getattr(self._stderr, attr)
+
+ def write(self, string):
+ self._stderr.write(string)
+ if '\n' not in string:
+ self._buffer += string
+ return
+
+ lines = string.split('\n')
+ lines[0] = self._buffer + lines[0]
+ self._buffer = lines[-1]
+ del lines[-1]
+
+ timestamp = time.time()
+ for line in lines:
+ self._interface.add_message(timestamp, "stderr", DEBUG_LEVEL_ERROR, line)