[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [nyx/master] Have LogGroup's add() accept LogEntries



commit a1f6177e8c08e203bac584ad3dd0f2f1cf9500de
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Mon Apr 27 09:17:32 2015 -0700

    Have LogGroup's add() accept LogEntries
    
    On reflection we always have a log entry on hand so lets just have the add
    method take that. The only thing that used the prior add() method was the
    tests.
---
 nyx/log_panel.py           |    4 ++--
 nyx/util/log.py            |    5 +----
 test/util/log/log_group.py |   42 +++++++++++++++++++++---------------------
 3 files changed, 24 insertions(+), 27 deletions(-)

diff --git a/nyx/log_panel.py b/nyx/log_panel.py
index 3bfa739..5016e09 100644
--- a/nyx/log_panel.py
+++ b/nyx/log_panel.py
@@ -148,7 +148,7 @@ class LogPanel(panel.Panel, threading.Thread):
         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)
+              self._msg_log.add(entry)
         except IOError as exc:
           log.info('Unable to read log located at %s: %s' % (logging_location, exc))
         except ValueError as exc:
@@ -756,7 +756,7 @@ class LogPanel(panel.Panel, threading.Thread):
         self.log_file = None
 
     with self.vals_lock:
-      self._msg_log.add(event.timestamp, event.type, event.message)
+      self._msg_log.add(event)
 
       # notifies the display that it has new content
 
diff --git a/nyx/util/log.py b/nyx/util/log.py
index 279a390..9a40411 100644
--- a/nyx/util/log.py
+++ b/nyx/util/log.py
@@ -135,10 +135,7 @@ class LogGroup(object):
     self._entries = []
     self._lock = threading.RLock()
 
-  def add(self, timestamp, type, message):
-    self.add_entry(LogEntry(timestamp, type, message))
-
-  def add_entry(self, entry):
+  def add(self, entry):
     with self._lock:
       duplicate = None
       our_day = entry.days_since()
diff --git a/test/util/log/log_group.py b/test/util/log/log_group.py
index d1f1f46..f4716ca 100644
--- a/test/util/log/log_group.py
+++ b/test/util/log/log_group.py
@@ -9,41 +9,41 @@ class TestLogGroup(unittest.TestCase):
     group = LogGroup(5)
     self.assertEqual(0, len(group))
 
-    group.add(1333738410, 'INFO', 'tor_lockfile_lock(): Locking "/home/atagar/.tor/lock"')
+    group.add(LogEntry(1333738410, 'INFO', 'tor_lockfile_lock(): Locking "/home/atagar/.tor/lock"'))
     self.assertEqual([LogEntry(1333738410, 'INFO', 'tor_lockfile_lock(): Locking "/home/atagar/.tor/lock"')], list(group))
     self.assertEqual(1, len(group))
 
-    group.add(1333738420, 'NYX_DEBUG', 'GETCONF MyFamily (runtime: 0.0007)')
-    group.add(1333738430, 'NOTICE', 'Bootstrapped 72%: Loading relay descriptors.')
-    group.add(1333738440, 'NOTICE', 'Bootstrapped 75%: Loading relay descriptors.')
-    group.add(1333738450, 'NOTICE', 'Bootstrapped 78%: Loading relay descriptors.')
+    group.add(LogEntry(1333738420, 'NYX_DEBUG', 'GETCONF MyFamily (runtime: 0.0007)'))
+    group.add(LogEntry(1333738430, 'NOTICE', 'Bootstrapped 72%: Loading relay descriptors.'))
+    group.add(LogEntry(1333738440, 'NOTICE', 'Bootstrapped 75%: Loading relay descriptors.'))
+    group.add(LogEntry(1333738450, 'NOTICE', 'Bootstrapped 78%: Loading relay descriptors.'))
     self.assertEqual(5, len(group))
 
     # group should now be full, adding more entries pops others off
 
-    group.add(1333738460, 'NOTICE', 'Bootstrapped 80%: Loading relay descriptors.')
+    group.add(LogEntry(1333738460, 'NOTICE', 'Bootstrapped 80%: Loading relay descriptors.'))
     self.assertFalse(LogEntry(1333738410, 'INFO', 'tor_lockfile_lock(): Locking "/home/atagar/.tor/lock"') in list(group))
     self.assertEqual(5, len(group))
 
     # try adding a bunch that will be deduplicated, and make sure we still maintain the size
 
-    group.add(1333738510, 'NOTICE', 'Bootstrapped 80%: Loading relay descriptors.')
-    group.add(1333738520, 'NOTICE', 'Bootstrapped 80%: Loading relay descriptors.')
-    group.add(1333738530, 'NOTICE', 'Bootstrapped 80%: Loading relay descriptors.')
-    group.add(1333738540, 'NOTICE', 'Bootstrapped 80%: Loading relay descriptors.')
-    group.add(1333738550, 'NOTICE', 'Bootstrapped 80%: Loading relay descriptors.')
-    group.add(1333738560, 'NOTICE', 'Bootstrapped 80%: Loading relay descriptors.')
-    group.add(1333738570, 'NOTICE', 'Bootstrapped 80%: Loading relay descriptors.')
+    group.add(LogEntry(1333738510, 'NOTICE', 'Bootstrapped 80%: Loading relay descriptors.'))
+    group.add(LogEntry(1333738520, 'NOTICE', 'Bootstrapped 80%: Loading relay descriptors.'))
+    group.add(LogEntry(1333738530, 'NOTICE', 'Bootstrapped 80%: Loading relay descriptors.'))
+    group.add(LogEntry(1333738540, 'NOTICE', 'Bootstrapped 80%: Loading relay descriptors.'))
+    group.add(LogEntry(1333738550, 'NOTICE', 'Bootstrapped 80%: Loading relay descriptors.'))
+    group.add(LogEntry(1333738560, 'NOTICE', 'Bootstrapped 80%: Loading relay descriptors.'))
+    group.add(LogEntry(1333738570, 'NOTICE', 'Bootstrapped 80%: Loading relay descriptors.'))
     self.assertEqual([1333738570, 1333738560, 1333738550, 1333738540, 1333738530], [e.timestamp for e in group])
     self.assertEqual(5, len(group))
 
   def test_deduplication(self):
     group = LogGroup(5)
-    group.add(1333738410, 'NOTICE', 'Bootstrapped 72%: Loading relay descriptors.')
-    group.add(1333738420, 'NOTICE', 'Bootstrapped 75%: Loading relay descriptors.')
-    group.add(1333738430, 'NYX_DEBUG', 'GETCONF MyFamily (runtime: 0.0007)')
-    group.add(1333738440, 'NOTICE', 'Bootstrapped 78%: Loading relay descriptors.')
-    group.add(1333738450, 'NOTICE', 'Bootstrapped 80%: Loading relay descriptors.')
+    group.add(LogEntry(1333738410, 'NOTICE', 'Bootstrapped 72%: Loading relay descriptors.'))
+    group.add(LogEntry(1333738420, 'NOTICE', 'Bootstrapped 75%: Loading relay descriptors.'))
+    group.add(LogEntry(1333738430, 'NYX_DEBUG', 'GETCONF MyFamily (runtime: 0.0007)'))
+    group.add(LogEntry(1333738440, 'NOTICE', 'Bootstrapped 78%: Loading relay descriptors.'))
+    group.add(LogEntry(1333738450, 'NOTICE', 'Bootstrapped 80%: Loading relay descriptors.'))
     self.assertEqual([1333738450, 1333738440, 1333738430, 1333738420, 1333738410], [e.timestamp for e in group])
 
     bootstrap_messages = [
@@ -59,7 +59,7 @@ class TestLogGroup(unittest.TestCase):
 
     # add another duplicate message that pops the last
 
-    group.add(1333738460, 'NOTICE', 'Bootstrapped 90%: Loading relay descriptors.')
+    group.add(LogEntry(1333738460, 'NOTICE', 'Bootstrapped 90%: Loading relay descriptors.'))
 
     bootstrap_messages = [
       'Bootstrapped 90%: Loading relay descriptors.',
@@ -74,7 +74,7 @@ class TestLogGroup(unittest.TestCase):
 
     # add another non-duplicate message that pops the last
 
-    group.add(1333738470, 'INFO', 'tor_lockfile_lock(): Locking "/home/atagar/.tor/lock"')
+    group.add(LogEntry(1333738470, 'INFO', 'tor_lockfile_lock(): Locking "/home/atagar/.tor/lock"'))
 
     bootstrap_messages = [
       'Bootstrapped 90%: Loading relay descriptors.',
@@ -92,7 +92,7 @@ class TestLogGroup(unittest.TestCase):
     test_log_path = os.path.join(os.path.dirname(__file__), 'data', 'daybreak_deduplication')
 
     for entry in reversed(list(read_tor_log(test_log_path))):
-      group.add_entry(entry)
+      group.add(entry)
 
     # Entries should consist of two days of results...
     #



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits