diff options
Diffstat (limited to 'portato')
-rw-r--r-- | portato/gui/views.py | 3 | ||||
-rw-r--r-- | portato/helper.py | 15 | ||||
-rw-r--r-- | portato/log.py | 17 |
3 files changed, 22 insertions, 13 deletions
diff --git a/portato/gui/views.py b/portato/gui/views.py index 26a8a89..9c55da0 100644 --- a/portato/gui/views.py +++ b/portato/gui/views.py @@ -18,6 +18,7 @@ import gtksourceview2 import logging from ..helper import warning +from ..log import add_handler class LazyView (object): def __init__ (self): @@ -147,7 +148,7 @@ class LogView (logging.Handler): for lvl, name, color in self.colors: self.buf.create_tag("log_%s" % name, foreground = color,weight = pango.WEIGHT_BOLD) - logging.getLogger("portatoLogger.stream").addHandler(self) + add_handler(self) def emit (self, record): diff --git a/portato/helper.py b/portato/helper.py index 8a312c0..71b7a3f 100644 --- a/portato/helper.py +++ b/portato/helper.py @@ -17,18 +17,17 @@ from __future__ import absolute_import import os, signal, logging, grp -debug = logging.getLogger("portatoLogger.stream").debug -info = logging.getLogger("portatoLogger.stream").info -warning = logging.getLogger("portatoLogger.stream").warning -error = logging.getLogger("portatoLogger.stream").error -critical = logging.getLogger("portatoLogger.stream").critical +from .log import set_log_level + +debug = logging.getLogger("portatoLogger").debug +info = logging.getLogger("portatoLogger").info +warning = logging.getLogger("portatoLogger").warning +error = logging.getLogger("portatoLogger").error +critical = logging.getLogger("portatoLogger").critical def N_ (s): return s -def set_log_level (lvl): - logging.getLogger("portatoLogger.stream").setLevel(lvl) - def send_signal_to_group (sig): """Sends a signal to all processes of our process group (w/o ourselves). diff --git a/portato/log.py b/portato/log.py index 97b1493..eb0c877 100644 --- a/portato/log.py +++ b/portato/log.py @@ -21,6 +21,11 @@ from .constants import SESSION_DIR (S_NOT, S_STREAM_ONLY, S_BOTH) = range(3) started = S_NOT +streamhandlers = [] # the handler printing visibile to the user + +def add_handler (h): + logging.getLogger("portatoLogger").addHandler(h) + streamhandlers.append(h) LOGFILE = os.path.join(SESSION_DIR, "portato.log") @@ -42,7 +47,7 @@ class OutputFormatter (logging.Formatter): if hasattr(sys.stderr, "fileno"): self.istty = os.isatty(sys.stderr.fileno()) else: - self.istty = False # no fileno -> save default + self.istty = False # no fileno -> safe default def format (self, record): string = logging.Formatter.format(self, record) @@ -67,7 +72,7 @@ def start(file = True): if started == S_BOTH: return - # logging: root (file) + # logging: file if file: if not (os.path.exists(SESSION_DIR) and os.path.isdir(SESSION_DIR)): os.mkdir(SESSION_DIR) @@ -87,7 +92,11 @@ def start(file = True): formatter = OutputFormatter("%(message)s (%(filename)s:%(lineno)s)") handler = logging.StreamHandler() handler.setFormatter(formatter) - logging.getLogger("portatoLogger.stream").addHandler(handler) - logging.getLogger("portatoLogger.stream").setLevel(logging.DEBUG) + add_handler(handler) started = S_BOTH if file else S_STREAM_ONLY + + +def set_log_level (lvl): + for h in streamhandlers: + h.setLevel(lvl) |