aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--voctocore/lib/loghandler.py35
-rwxr-xr-xvoctocore/voctocore.py11
-rw-r--r--voctogui/lib/loghandler.py35
-rwxr-xr-xvoctogui/voctogui.py11
4 files changed, 80 insertions, 12 deletions
diff --git a/voctocore/lib/loghandler.py b/voctocore/lib/loghandler.py
new file mode 100644
index 0000000..4e48c7d
--- /dev/null
+++ b/voctocore/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))
diff --git a/voctocore/voctocore.py b/voctocore/voctocore.py
index ad3f1cf..3a4125a 100755
--- a/voctocore/voctocore.py
+++ b/voctocore/voctocore.py
@@ -24,6 +24,7 @@ GObject.threads_init()
from lib.args import Args
from lib.pipeline import Pipeline
from lib.controlserver import ControlServer
+from lib.loghandler import LogHandler
# main class
class Voctocore(object):
@@ -56,6 +57,9 @@ def main():
# configure logging
docolor = (Args.color == 'always') or (Args.color == 'auto' and sys.stderr.isatty())
+ handler = LogHandler(docolor)
+ logging.root.addHandler(handler)
+
if Args.verbose >= 2:
level = logging.DEBUG
elif Args.verbose == 1:
@@ -63,12 +67,7 @@ def main():
else:
level = logging.WARNING
- if docolor:
- format = '\x1b[33m%(levelname)8s\x1b[0m \x1b[32m%(name)s\x1b[0m: %(message)s'
- else:
- format = '%(levelname)8s %(name)s: %(message)s'
-
- logging.basicConfig(level=level, format=format)
+ logging.root.setLevel(level)
# make killable by ctrl-c
logging.debug('setting SIGINT handler')
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))
diff --git a/voctogui/voctogui.py b/voctogui/voctogui.py
index 9f0cc0a..083b004 100755
--- a/voctogui/voctogui.py
+++ b/voctogui/voctogui.py
@@ -29,6 +29,7 @@ Gtk.init([])
from lib.args import Args
from lib.config import Config
from lib.ui import Ui
+from lib.loghandler import LogHandler
import lib.connection as Connection
@@ -85,6 +86,9 @@ def main():
# configure logging
docolor = (Args.color == 'always') or (Args.color == 'auto' and sys.stderr.isatty())
+ handler = LogHandler(docolor)
+ logging.root.addHandler(handler)
+
if Args.verbose >= 2:
level = logging.DEBUG
elif Args.verbose == 1:
@@ -92,12 +96,7 @@ def main():
else:
level = logging.WARNING
- if docolor:
- format = '\x1b[33m%(levelname)8s\x1b[0m \x1b[32m%(name)s\x1b[0m: %(message)s'
- else:
- format = '%(levelname)8s %(name)s: %(message)s'
-
- logging.basicConfig(level=level, format=format)
+ logging.root.setLevel(level)
# make killable by ctrl-c
logging.debug('setting SIGINT handler')