commit 6e40473ba31f50079aff1b4f5bf2d1cdaca58e4c
Author: Damian Johnson <atagar(a)torproject.org>
Date: Wed Jun 8 10:26:48 2016 -0700
Revise handlign for invalid --log input
Few change to the previous commit...
* We didn't recognize the nyx runlevels (NYX_NOTICE and such).
* Our getinfo request didn't have a default so it could cause us to stacktrace.
* Making this a bit simpler.
---
nyx/panel/log.py | 30 ++++++++----------------------
1 file changed, 8 insertions(+), 22 deletions(-)
diff --git a/nyx/panel/log.py b/nyx/panel/log.py
index 482b567..9de7353 100644
--- a/nyx/panel/log.py
+++ b/nyx/panel/log.py
@@ -31,27 +31,6 @@ def conf_handler(key, value):
return max(1000, value)
-def validate_events(events):
- """
- Check whether the events are any one of Tor runlevels, Nyx runlevels or
- Tor events. If not, return the default events.
- """
- valid_events = tor_controller().get_info('events/names').split()
- accepted_events, invalid_events = set(), set()
-
- events = events.split(',')
- for event in events:
- if event in valid_events:
- accepted_events.update([event])
- else:
- invalid_events.update([event])
-
- if invalid_events:
- return ['NOTICE', 'WARN', 'ERR', 'NYX_NOTICE', 'NYX_WARNING', 'NYX_ERROR']
- else:
- return accepted_events
-
-
CONFIG = conf.config_dict('nyx', {
'attr.log_color': {},
'cache.log_panel.size': 1000,
@@ -89,7 +68,14 @@ class LogPanel(nyx.panel.DaemonPanel):
def __init__(self):
nyx.panel.DaemonPanel.__init__(self, 'log', UPDATE_RATE)
- logged_events = validate_events(CONFIG['startup.events'])
+ logged_events = CONFIG['startup.events'].split(',')
+ tor_events = tor_controller().get_info('events/names', '').split()
+ invalid_events = filter(lambda event: not event.startswith('NYX_') and event not in tor_events, logged_events)
+
+ if invalid_events:
+ logged_events = ['NOTICE', 'WARN', 'ERR', 'NYX_NOTICE', 'NYX_WARNING', 'NYX_ERROR']
+ log.warn("Your --log argument had the following events tor doesn't recognize: %s" % ', '.join(invalid_events))
+
self._event_log = nyx.log.LogGroup(CONFIG['cache.log_panel.size'], group_by_day = True)
self._event_log_paused = None
self._event_types = nyx.log.listen_for_events(self._register_tor_event, logged_events)