[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [arm/master] Moving event logging selection to the log panel
commit 4986780baff0740a7c55eaf7717697f54e305a5d
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Thu May 12 20:45:55 2011 -0700
Moving event logging selection to the log panel
---
src/cli/controller.py | 77 -------------------------------------------------
src/cli/logPanel.py | 56 ++++++++++++++++++++++++++++++++++-
2 files changed, 54 insertions(+), 79 deletions(-)
diff --git a/src/cli/controller.py b/src/cli/controller.py
index 035ef07..84205cb 100644
--- a/src/cli/controller.py
+++ b/src/cli/controller.py
@@ -277,32 +277,6 @@ def setPauseState(panels, monitorIsPaused, currentPage, overwrite=False):
for key in allPanels: panels[key].setPaused(overwrite or monitorIsPaused or (key not in PAGES[currentPage] and key not in PAGE_S))
-def setEventListening(selectedEvents, isBlindMode):
- # creates a local copy, note that a suspected python bug causes *very*
- # puzzling results otherwise when trying to discard entries (silently
- # returning out of this function!)
- events = set(selectedEvents)
- isLoggingUnknown = "UNKNOWN" in events
-
- # removes special types only used in arm (UNKNOWN, TORCTL, ARM_DEBUG, etc)
- toDiscard = []
- for eventType in events:
- if eventType not in logPanel.TOR_EVENT_TYPES.values(): toDiscard += [eventType]
-
- for eventType in list(toDiscard): events.discard(eventType)
-
- # adds events unrecognized by arm if we're listening to the 'UNKNOWN' type
- if isLoggingUnknown:
- events.update(set(logPanel.getMissingEventTypes()))
-
- setEvents = torTools.getConn().setControllerEvents(list(events))
-
- # temporary hack for providing user selected events minus those that failed
- # (wouldn't be a problem if I wasn't storing tor and non-tor events together...)
- returnVal = list(selectedEvents.difference(torTools.FAILED_EVENTS))
- returnVal.sort() # alphabetizes
- return returnVal
-
def connResetListener(conn, eventType):
"""
Pauses connection resolution when tor's shut down, and resumes if started
@@ -507,7 +481,6 @@ def drawTorMonitor(stdscr, startTime, loggedEvents, isBlindMode):
if isSuccessful: panels["graph"].updateInterval = 4
# tells Tor to listen to the events we're interested
- loggedEvents = setEventListening(loggedEvents, isBlindMode)
#panels["log"].loggedEvents = loggedEvents # strips any that couldn't be set
panels["log"].setLoggedEvents(loggedEvents) # strips any that couldn't be set
@@ -869,56 +842,6 @@ def drawTorMonitor(stdscr, startTime, loggedEvents, isBlindMode):
panel.CURSES_LOCK.release()
panels["graph"].redraw(True)
- elif page == 0 and (key == ord('e') or key == ord('E')):
- # allow user to enter new types of events to log - unchanged if left blank
- panel.CURSES_LOCK.acquire()
- try:
- setPauseState(panels, isPaused, page, True)
-
- # provides prompt
- panels["control"].setMsg("Events to log: ")
- panels["control"].redraw(True)
-
- # lists event types
- popup = panels["popup"]
- popup.height = 11
- popup.recreate(stdscr, 80)
-
- popup.clear()
- popup.win.box()
- popup.addstr(0, 0, "Event Types:", curses.A_STANDOUT)
- lineNum = 1
- for line in logPanel.EVENT_LISTING.split("\n"):
- line = line[6:]
- popup.addstr(lineNum, 1, line)
- lineNum += 1
- popup.refresh()
-
- # gets user input (this blocks monitor updates)
- eventsInput = panels["control"].getstr(0, 15)
- if eventsInput: eventsInput = eventsInput.replace(' ', '') # strips spaces
-
- # it would be nice to quit on esc, but looks like this might not be possible...
- if eventsInput:
- try:
- expandedEvents = logPanel.expandEvents(eventsInput)
- loggedEvents = setEventListening(expandedEvents, isBlindMode)
- panels["log"].setLoggedEvents(loggedEvents)
- except ValueError, exc:
- panels["control"].setMsg("Invalid flags: %s" % str(exc), curses.A_STANDOUT)
- panels["control"].redraw(True)
- time.sleep(2)
-
- # reverts popup dimensions
- popup.height = 9
- popup.recreate(stdscr, 80)
-
- panels["control"].setMsg(CTL_PAUSED if isPaused else CTL_HELP)
- setPauseState(panels, isPaused, page)
- finally:
- panel.CURSES_LOCK.release()
-
- panels["graph"].redraw(True)
else:
for pagePanel in getPanels(page + 1):
isKeystrokeConsumed = pagePanel.handleKey(key)
diff --git a/src/cli/logPanel.py b/src/cli/logPanel.py
index 745cb57..75cdab5 100644
--- a/src/cli/logPanel.py
+++ b/src/cli/logPanel.py
@@ -163,6 +163,28 @@ def getMissingEventTypes():
return [event for event in torEventTypes if not event in armEventTypes]
else: return None # GETINFO call failed
+def setEventListening(events):
+ """
+ Configures the events Tor listens for, filtering non-tor events from what we
+ request from the controller. This returns a sorted list of the events we
+ successfully set.
+
+ Arguments:
+ events - event types to attempt to set
+ """
+
+ events = set(events) # drops duplicates
+ torEvents = events.intersection(set(TOR_EVENT_TYPES.values()))
+
+ # adds events unrecognized by arm if we're listening to the 'UNKNOWN' type
+ if "UNKNOWN" in events:
+ torEvents.update(set(getMissingEventTypes()))
+
+ setEvents = torTools.getConn().setControllerEvents(list(torEvents))
+
+ # provides back the input set minus events we failed to set
+ return sorted(events.difference(torTools.FAILED_EVENTS))
+
def loadLogMessages():
"""
Fetches a mapping of common log messages to their runlevels from the config.
@@ -552,6 +574,10 @@ class LogPanel(panel.Panel, threading.Thread):
# collapses duplicate log entries if false, showing only the most recent
self.showDuplicates = self._config["features.log.showDuplicateEntries"]
+ # restricts the input to the set of events we can listen to, and
+ # configures the controller to liten to them
+ loggedEvents = setEventListening(loggedEvents)
+
self.setPauseAttr("msgLog") # tracks the message log when we're paused
self.msgLog = [] # log entries, sorted by the timestamp
self.loggedEvents = loggedEvents # events we're listening to
@@ -693,9 +719,12 @@ class LogPanel(panel.Panel, threading.Thread):
"""
if eventTypes == self.loggedEvents: return
-
self.valsLock.acquire()
- self.loggedEvents = eventTypes
+
+ # configures the controller to listen for these tor events, and provides
+ # back a subset without anything we're failing to listen to
+ setTypes = setEventListening(eventTypes)
+ self.loggedEvents = setTypes
self.redraw(True)
self.valsLock.release()
@@ -815,6 +844,29 @@ class LogPanel(panel.Panel, threading.Thread):
panel.CURSES_LOCK.release()
if len(self.filterOptions) > MAX_REGEX_FILTERS: del self.filterOptions[MAX_REGEX_FILTERS:]
+ elif key == ord('e') or key == ord('E'):
+ # allow user to enter new types of events to log - unchanged if left blank
+ popup, width, height = popups.init(11, 80)
+
+ if popup:
+ try:
+ # displays the available flags
+ popup.win.box()
+ popup.addstr(0, 0, "Event Types:", curses.A_STANDOUT)
+ eventLines = EVENT_LISTING.split("\n")
+
+ for i in range(len(eventLines)):
+ popup.addstr(i + 1, 1, eventLines[i][6:])
+
+ popup.win.refresh()
+
+ userInput = popups.inputPrompt("Events to log: ")
+ if userInput:
+ userInput = userInput.replace(' ', '') # strips spaces
+ try: self.setLoggedEvents(expandEvents(userInput))
+ except ValueError, exc:
+ popups.showMsg("Invalid flags: %s" % str(exc), 2)
+ finally: popups.finalize()
else: isKeystrokeConsumed = False
return isKeystrokeConsumed
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits