[tor-commits] [nyx/master] Fix nyx error logging

atagar at torproject.org atagar at torproject.org
Mon Apr 18 20:23:16 UTC 2016


commit 26ded909760b5e143e8a6bf061b8fa9b1d44ef39
Author: Damian Johnson <atagar at torproject.org>
Date:   Mon Apr 18 11:33:43 2016 -0700

    Fix nyx error logging
    
    Log messages at our error level weren't being displayed. This is because we
    logged them as 'NYX_ERROR' but expected 'NYX_ERR'.
    
    We were attempted to name our runlevels after tor but on reflection lets not -
    tor's names suck. Showing our actual runlevel names which are...
    
     * WARN => WARNING
     * ERR => ERROR
---
 nyx/arguments.py            | 10 ++++------
 nyx/log.py                  | 14 +++++++++++---
 nyx/panel/log.py            |  3 ---
 nyx/settings/attributes.cfg |  4 ++--
 4 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/nyx/arguments.py b/nyx/arguments.py
index e70278b..ad8ea4a 100644
--- a/nyx/arguments.py
+++ b/nyx/arguments.py
@@ -10,6 +10,7 @@ import getopt
 import os
 
 import nyx
+import nyx.log
 
 import stem.util.connection
 
@@ -215,12 +216,9 @@ def expand_events(flags):
 
   expanded_events, invalid_flags = set(), ''
 
-  tor_runlevels = ['DEBUG', 'INFO', 'NOTICE', 'WARN', 'ERR']
-  nyx_runlevels = ['NYX_' + runlevel for runlevel in tor_runlevels]
-
   for flag in flags:
     if flag == 'A':
-      return set(list(TOR_EVENT_TYPES) + nyx_runlevels + ['UNKNOWN'])
+      return set(list(TOR_EVENT_TYPES) + nyx.log.NYX_RUNLEVELS + ['UNKNOWN'])
     elif flag == 'X':
       return set()
     elif flag in 'DINWE12345':
@@ -238,9 +236,9 @@ def expand_events(flags):
         runlevel_index = 4
 
       if flag in 'DINWE':
-        runlevels = tor_runlevels[runlevel_index:]
+        runlevels = nyx.log.TOR_RUNLEVELS[runlevel_index:]
       elif flag in '12345':
-        runlevels = nyx_runlevels[runlevel_index:]
+        runlevels = nyx.log.NYX_RUNLEVELS[runlevel_index:]
 
       expanded_events.update(set(runlevels))
     elif flag == 'U':
diff --git a/nyx/log.py b/nyx/log.py
index ec09c3f..2a60a9e 100644
--- a/nyx/log.py
+++ b/nyx/log.py
@@ -61,6 +61,7 @@ except ImportError:
   from stem.util.lru_cache import lru_cache
 
 TOR_RUNLEVELS = ['DEBUG', 'INFO', 'NOTICE', 'WARN', 'ERR']
+NYX_RUNLEVELS = ['NYX_DEBUG', 'NYX_INFO', 'NYX_NOTICE', 'NYX_WARNING', 'NYX_ERROR']
 TIMEZONE_OFFSET = time.altzone if time.localtime()[8] else time.timezone
 
 
@@ -133,9 +134,16 @@ def condense_runlevels(*events):
       tor_runlevels.append(r)
       events.remove(r)
 
-    if 'NYX_%s' % r in events:
+    if r == 'WARN':
+      nyx_runlevel = 'NYX_WARNING'
+    elif r == 'ERR':
+      nyx_runlevel = 'NYX_ERROR'
+    else:
+      nyx_runlevel = 'NYX_%s' % r
+
+    if nyx_runlevel in events:
       nyx_runlevels.append(r)
-      events.remove('NYX_%s' % r)
+      events.remove(nyx_runlevel)
 
   tor_ranges = ranges(tor_runlevels)
   nyx_ranges = ranges(nyx_runlevels)
@@ -180,7 +188,7 @@ def listen_for_events(listener, events):
   # accounts for runlevel naming difference
 
   tor_events = events.intersection(set(nyx.arguments.TOR_EVENT_TYPES.values()))
-  nyx_events = events.intersection(set(['NYX_%s' % runlevel for runlevel in TOR_RUNLEVELS]))
+  nyx_events = events.intersection(set(NYX_RUNLEVELS))
 
   # adds events unrecognized by nyx if we're listening to the 'UNKNOWN' type
 
diff --git a/nyx/panel/log.py b/nyx/panel/log.py
index 3e8932d..278c633 100644
--- a/nyx/panel/log.py
+++ b/nyx/panel/log.py
@@ -378,9 +378,6 @@ class LogPanel(nyx.panel.DaemonPanel):
     self._register_event(nyx.log.LogEntry(event.arrived_at, event.type, msg))
 
   def _register_nyx_event(self, record):
-    if record.levelname == 'WARNING':
-      record.levelname = 'WARN'
-
     self._register_event(nyx.log.LogEntry(int(record.created), 'NYX_%s' % record.levelname, record.msg))
 
   def _register_event(self, event):
diff --git a/nyx/settings/attributes.cfg b/nyx/settings/attributes.cfg
index fcc78f3..37e8ebc 100644
--- a/nyx/settings/attributes.cfg
+++ b/nyx/settings/attributes.cfg
@@ -48,8 +48,8 @@ attr.log_color ERR => Red
 attr.log_color NYX_DEBUG => Magenta
 attr.log_color NYX_INFO => Blue
 attr.log_color NYX_NOTICE => Green
-attr.log_color NYX_WARN => Yellow
-attr.log_color NYX_ERR => Red
+attr.log_color NYX_WARNING => Yellow
+attr.log_color NYX_ERROR => Red
 
 attr.log_color CIRC => Yellow
 attr.log_color BW => Cyan





More information about the tor-commits mailing list