commit 82dff415fd168552c7f862fcafc193fe0ed07a7c
Author: Ondrej Lichtner <olichtne(a)redhat.com>
Date: Fri Mar 8 16:24:38 2013 +0100
LoggingHandler: add TransmitHandler
This handler will transmit the emmited logging records to a selected
target. The record transmission is via the use of the send_data
function so the target can be a socket or a Connection type object.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
lnst/Common/LoggingHandler.py | 19 +++++++++++++++++++
1 files changed, 19 insertions(+), 0 deletions(-)
---
diff --git a/lnst/Common/LoggingHandler.py b/lnst/Common/LoggingHandler.py
index cea0529..3fd8919 100644
--- a/lnst/Common/LoggingHandler.py
+++ b/lnst/Common/LoggingHandler.py
@@ -17,6 +17,7 @@ olichtne(a)redhat.com (Ondrej Lichtner)
import socket, struct, pickle
import logging
import xmlrpclib
+from lnst.Common.ConnectionHandler import send_data
class LogBuffer(logging.Handler):
"""
@@ -60,3 +61,21 @@ class LogBuffer(logging.Handler):
def close(self):
self.flush()
logging.Handler.close(self)
+
+class TransmitHandler(logging.Handler):
+ def __init__(self, target):
+ logging.Handler.__init__(self)
+ self.target = target
+
+ def emit(self, record):
+ r = dict(record.__dict__)
+ r['msg'] = record.getMessage()
+ r['args'] = None
+ r['exc_info'] = None
+
+ data = {"type": "log", "record": r}
+
+ send_data(self.target, data)
+
+ def close(self):
+ logging.Handler.close(self)
Show replies by thread