[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [arm/master] Support logging of arm events.
commit d5556ad4ce0c43d0aca1b287ad59c3a90bd923c5
Author: Kamran Riaz Khan <krkhan@xxxxxxxxxxxxxx>
Date: Mon Jun 20 16:55:05 2011 +0500
Support logging of arm events.
---
src/gui/__init__.py | 2 +-
src/gui/arm.xml | 8 +------
src/gui/controller.py | 14 +++++++-----
src/gui/logPanel.py | 56 +++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 66 insertions(+), 14 deletions(-)
diff --git a/src/gui/__init__.py b/src/gui/__init__.py
index f461b3e..b700273 100644
--- a/src/gui/__init__.py
+++ b/src/gui/__init__.py
@@ -2,5 +2,5 @@
Panels, popups, and handlers comprising the arm user interface.
"""
-__all__ = ["controller"]
+__all__ = ["controller", "logPanel"]
diff --git a/src/gui/arm.xml b/src/gui/arm.xml
index 11f5c63..8cbb924 100644
--- a/src/gui/arm.xml
+++ b/src/gui/arm.xml
@@ -692,11 +692,5 @@ each direction. (Default: 0) </span></property>
</object>
</child>
</object>
- <object class="GtkTextBuffer" id="textbuffer_log">
- <property name="text" translatable="yes">16:09:20 [NOTICE] Bootstrapped 90%: Establishing a Tor circuit.
-16:09:23 [NOTICE] Tor has successfully opened a circuit. Looks like client functionality is working.
-16:09:23 [NOTICE] Tor has successfully opened a circuit. Looks like client functionality is working.
-16:09:24 [NOTICE] Bootstrapped 100%: Done.
-</property>
- </object>
+ <object class="GtkTextBuffer" id="textbuffer_log"/>
</interface>
diff --git a/src/gui/controller.py b/src/gui/controller.py
index 4da82c9..8f27df4 100644
--- a/src/gui/controller.py
+++ b/src/gui/controller.py
@@ -1,7 +1,8 @@
import gobject
import gtk
-from util import torTools
+from util import log, torTools
+from gui import logPanel
from gui.graphing import bandwidthStats
gobject.threads_init()
@@ -17,14 +18,15 @@ class GuiController:
self.bwStats = bandwidthStats.BandwidthStats(self.builder)
self.bwStats.pack_widgets()
+ self.logPanel = logPanel.LogPanel(self.builder)
+ self.logPanel.pack_widgets()
+
+ log.log(log.DEBUG, "Hello World!")
+ log.log(log.ERR, "Hello Again!")
+
def run(self):
window = self.builder.get_object('window_main')
- textbuffer = self.builder.get_object('textbuffer_log')
- conn = torTools.getConn()
- torPid = conn.getMyPid()
- textbuffer.set_text("Tor pid: %s" % torPid)
-
window.show_all()
gtk.main()
diff --git a/src/gui/logPanel.py b/src/gui/logPanel.py
new file mode 100644
index 0000000..174ed64
--- /dev/null
+++ b/src/gui/logPanel.py
@@ -0,0 +1,56 @@
+"""
+Base class for implementing graphing functionality.
+"""
+
+import random
+import sys
+
+from collections import deque
+
+import gobject
+import gtk
+
+from TorCtl import TorCtl
+from util import log, uiTools, torTools
+
+from cli.logPanel import RUNLEVEL_EVENT_COLOR, LogEntry
+
+class LogPanel:
+ def __init__(self, builder):
+ self.builder = builder
+
+ self.msgLog = deque()
+
+ log.LOG_LOCK.acquire()
+ try:
+ armRunlevels = [log.DEBUG, log.INFO, log.NOTICE, log.WARN, log.ERR]
+ log.addListeners(armRunlevels, self._register_arm_event)
+ finally:
+ log.LOG_LOCK.release()
+
+ textbuffer = self.builder.get_object('textbuffer_log')
+
+ for color in RUNLEVEL_EVENT_COLOR.values():
+ textbuffer.create_tag(color, foreground=color)
+
+ gobject.timeout_add(1000, self.print_log)
+
+ def print_log(self):
+ textbuffer = self.builder.get_object('textbuffer_log')
+ start, end = textbuffer.get_bounds()
+ textbuffer.delete(start, end)
+
+ for entry in self.msgLog:
+ iter = textbuffer.get_iter_at_mark(textbuffer.get_insert())
+ textbuffer.insert_with_tags_by_name(iter, entry.getDisplayMessage() + "\n", entry.color)
+
+ def register_event(self, event):
+ self.msgLog.appendleft(event)
+
+ def pack_widgets(self):
+ pass
+
+ def _register_arm_event(self, level, msg, eventTime):
+ eventColor = RUNLEVEL_EVENT_COLOR[level]
+ self.register_event(LogEntry(eventTime, "ARM_%s" % level, msg, eventColor))
+
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits