[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [nyx/master] Move log colors to config
commit 552bdf3756af1e3bc254bc5c0e7c7f3019d7cd69
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Sat Apr 11 16:23:16 2015 -0700
Move log colors to config
This is a simple 'event type => color' mapping so no need for it to be littered
throughout our code.
---
nyx/config/attributes.cfg | 18 ++++++++++++++++++
nyx/log_panel.py | 38 +++++++++-----------------------------
2 files changed, 27 insertions(+), 29 deletions(-)
diff --git a/nyx/config/attributes.cfg b/nyx/config/attributes.cfg
index 30bfafb..fe24120 100644
--- a/nyx/config/attributes.cfg
+++ b/nyx/config/attributes.cfg
@@ -39,3 +39,21 @@ attr.graph.header.secondary bandwidth => Upload
attr.graph.header.secondary connections => Outbound
attr.graph.header.secondary resources => Memory
+attr.log_color DEBUG => magenta
+attr.log_color INFO => blue
+attr.log_color NOTICE => green
+attr.log_color WARN => yellow
+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 CIRC => yellow
+attr.log_color BW => cyan
+attr.log_color NS => blue
+attr.log_color NEWCONSENSUS => blue
+attr.log_color GUARD => yellow
+
diff --git a/nyx/log_panel.py b/nyx/log_panel.py
index 33af9dd..ddf2c6e 100644
--- a/nyx/log_panel.py
+++ b/nyx/log_panel.py
@@ -28,14 +28,6 @@ try:
except ImportError:
from stem.util.lru_cache import lru_cache
-RUNLEVEL_EVENT_COLOR = {
- log.DEBUG: 'magenta',
- log.INFO: 'blue',
- log.NOTICE: 'green',
- log.WARN: 'yellow',
- log.ERR: 'red',
-}
-
DAYBREAK_EVENT = 'DAYBREAK' # special event for marking when the date changes
TIMEZONE_OFFSET = time.altzone if time.localtime()[8] else time.timezone
@@ -66,6 +58,7 @@ CONFIG = conf.config_dict('nyx', {
'cache.log_panel.size': 1000,
'msg.misc.event_types': '',
'tor.chroot': '',
+ 'attr.log_color': {},
}, conf_handler)
DUPLICATE_MSG = ' [%i duplicate%s hidden]'
@@ -283,11 +276,11 @@ class LogEntry():
color - color of the log entry
"""
- def __init__(self, timestamp, event_type, msg, color):
+ def __init__(self, timestamp, event_type, msg):
self.timestamp = timestamp
self.type = event_type
self.msg = msg
- self.color = color
+ self.color = CONFIG['attr.log_color'].get(event_type, 'white')
@lru_cache()
def get_display_message(self, include_date = False):
@@ -415,8 +408,7 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
if record.levelname == 'WARNING':
record.levelname = 'WARN'
- event_color = RUNLEVEL_EVENT_COLOR[record.levelname]
- self.register_event(LogEntry(int(record.created), 'NYX_%s' % record.levelname, record.msg, event_color))
+ self.register_event(LogEntry(int(record.created), 'NYX_%s' % record.levelname, record.msg))
def reprepopulate_events(self):
"""
@@ -441,7 +433,7 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
try:
for entry in read_tor_log(logging_location, read_limit):
if entry.runlevel in set_runlevels:
- self.msg_log.append(LogEntry(entry.timestamp, entry.runlevel, entry.message, RUNLEVEL_EVENT_COLOR[entry.runlevel]))
+ self.msg_log.append(LogEntry(entry.timestamp, entry.runlevel, entry.message))
except IOError as exc:
log.info('Unable to read log located at %s: %s' % (logging_location, exc))
except ValueError as exc:
@@ -471,26 +463,14 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
register_event().
"""
- msg, color = ' '.join(str(event).split(' ')[1:]), 'white'
+ msg = ' '.join(str(event).split(' ')[1:])
- if isinstance(event, events.CircuitEvent):
- color = 'yellow'
- elif isinstance(event, events.BandwidthEvent):
- color = 'cyan'
+ if isinstance(event, events.BandwidthEvent):
msg = 'READ: %i, WRITTEN: %i' % (event.read, event.written)
elif isinstance(event, events.LogEvent):
- color = RUNLEVEL_EVENT_COLOR[event.runlevel]
msg = event.message
- elif isinstance(event, events.NetworkStatusEvent):
- color = 'blue'
- elif isinstance(event, events.NewConsensusEvent):
- color = 'magenta'
- elif isinstance(event, events.GuardEvent):
- color = 'yellow'
- elif event.type not in nyx.arguments.TOR_EVENT_TYPES.values():
- color = 'red' # unknown event type
-
- self.register_event(LogEntry(event.arrived_at, event.type, msg, color))
+
+ self.register_event(LogEntry(event.arrived_at, event.type, msg))
def register_event(self, event):
"""
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits