[tor-commits] [nyx/master] Don't clear log when re-attaching to tor

atagar at torproject.org atagar at torproject.org
Tue May 5 05:42:06 UTC 2015


commit faa6dd144d254e201b547e86341be7dbc44d1d34
Author: Damian Johnson <atagar at torproject.org>
Date:   Sun Apr 26 22:21:15 2015 -0700

    Don't clear log when re-attaching to tor
    
    Idea was to ensure logs concerned the tor instance we're attached to, but not
    sure this is actually desirable. When attaching to a restarted tor instance no
    reason to clear the nyx log panel.
---
 nyx/log_panel.py |   63 ++++++++++++++++++++----------------------------------
 1 file changed, 23 insertions(+), 40 deletions(-)

diff --git a/nyx/log_panel.py b/nyx/log_panel.py
index 3e83de5..fe75e18 100644
--- a/nyx/log_panel.py
+++ b/nyx/log_panel.py
@@ -137,7 +137,23 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
 
     self._last_logged_events = []
 
-    self.reprepopulate_events()
+    # fetches past tor events from log file, if available
+
+    if CONFIG['features.log.prepopulate']:
+      set_runlevels = list(set.intersection(set(self.logged_events), set(list(log.Runlevel))))
+      read_limit = CONFIG['features.log.prepopulateReadLimit']
+
+      logging_location = log_file_path()
+
+      if logging_location:
+        try:
+          for entry in reversed(list(read_tor_log(logging_location, read_limit))):
+            if entry.type in set_runlevels:
+              self._msg_log.add(entry.timestamp, entry.type, entry.message)
+        except IOError as exc:
+          log.info('Unable to read log located at %s: %s' % (logging_location, exc))
+        except ValueError as exc:
+          log.info(str(exc))
 
     # leaving last_content_height as being too low causes initialization problems
 
@@ -146,7 +162,12 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
     # adds listeners for tor and stem events
 
     controller = tor_controller()
-    controller.add_status_listener(self._reset_listener)
+
+    def reset_listener(controller, event_type, _):
+      if event_type == State.CLOSED:
+        log.notice('Tor control port closed')
+
+    controller.add_status_listener(reset_listener)
 
     # opens log file if we'll be saving entries
 
@@ -179,34 +200,6 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
 
     self.register_event(LogEntry(int(record.created), 'NYX_%s' % record.levelname, record.msg))
 
-  def reprepopulate_events(self):
-    """
-    Clears the event log and repopulates it from the nyx and tor backlogs.
-    """
-
-    with self.vals_lock:
-      # clears the event log
-
-      self._msg_log = LogGroup(CONFIG['cache.log_panel.size'], group_by_day = CONFIG['features.log.showDateDividers'])
-
-      # fetches past tor events from log file, if available
-
-      if CONFIG['features.log.prepopulate']:
-        set_runlevels = list(set.intersection(set(self.logged_events), set(list(log.Runlevel))))
-        read_limit = CONFIG['features.log.prepopulateReadLimit']
-
-        logging_location = log_file_path()
-
-        if logging_location:
-          try:
-            for entry in reversed(list(read_tor_log(logging_location, read_limit))):
-              if entry.type in set_runlevels:
-                self._msg_log.add(entry.timestamp, entry.type, entry.message)
-          except IOError as exc:
-            log.info('Unable to read log located at %s: %s' % (logging_location, exc))
-          except ValueError as exc:
-            log.info(str(exc))
-
   def set_duplicate_visability(self, is_visible):
     """
     Sets if duplicate log entries are collaped or expanded.
@@ -779,13 +772,3 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
     # provides back the input set minus events we failed to set
 
     return sorted(tor_events.union(nyx_events))
-
-  def _reset_listener(self, controller, event_type, _):
-    # if we're attaching to a new tor instance then clears the log and
-    # prepopulates it with the content belonging to this instance
-
-    if event_type == State.INIT:
-      self.reprepopulate_events()
-      self.redraw(True)
-    elif event_type == State.CLOSED:
-      log.notice('Tor control port closed')





More information about the tor-commits mailing list