aboutsummaryrefslogtreecommitdiff
path: root/voctogui/lib
diff options
context:
space:
mode:
authorMaZderMind <git@mazdermind.de>2015-11-26 17:15:19 +0100
committerMaZderMind <git@mazdermind.de>2015-11-26 17:15:19 +0100
commit6c415915a5980ed8f750a6d73d243b2a4842adf2 (patch)
tree8a08f422270b0c5c86257461dc256ea30f6255b4 /voctogui/lib
parentd513ed2bb25250945daebb4804324cd5e6ad5048 (diff)
color warnings and errors differently, fixes #24
Diffstat (limited to 'voctogui/lib')
-rw-r--r--voctogui/lib/loghandler.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/voctogui/lib/loghandler.py b/voctogui/lib/loghandler.py
new file mode 100644
index 0000000..4e48c7d
--- /dev/null
+++ b/voctogui/lib/loghandler.py
@@ -0,0 +1,35 @@
+#!/usr/bin/python3
+import logging
+
+class LogFormatter(logging.Formatter):
+ def __init__(self, docolor):
+ super().__init__()
+ self.docolor = docolor
+
+ def formatMessage(self, record):
+ if self.docolor:
+ c_lvl = 33
+ c_mod = 32
+ c_msg = 0
+
+ if record.levelno == logging.WARNING:
+ c_lvl = 31
+ #c_mod = 33
+ c_msg = 33
+
+ elif record.levelno > logging.WARNING:
+ c_lvl = 31
+ c_mod = 31
+ c_msg = 31
+
+ fmt = '\x1b['+str(c_lvl)+'m%(levelname)8s\x1b[0m \x1b['+str(c_mod)+'m%(name)s\x1b['+str(c_msg)+'m: %(message)s\x1b[0m'
+ else:
+ fmt = '%(levelname)8s %(name)s: %(message)s'
+
+ return fmt % record.__dict__
+
+
+class LogHandler(logging.StreamHandler):
+ def __init__(self, docolor):
+ super().__init__()
+ self.setFormatter(LogFormatter(docolor))