summaryrefslogtreecommitdiff
path: root/portato/log.py
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.net>2009-02-03 21:14:41 +0100
committerRené 'Necoro' Neumann <necoro@necoro.net>2009-02-03 21:14:41 +0100
commit77fa3af6a811e95ca7a9704e804ed22b5928aba5 (patch)
treebda7fe52672faa0734581549eaf3a6fbac9ba2b9 /portato/log.py
parent4250e6969b807bec849d9c9078ec5206333ac339 (diff)
downloadportato-77fa3af6a811e95ca7a9704e804ed22b5928aba5.tar.gz
portato-77fa3af6a811e95ca7a9704e804ed22b5928aba5.tar.bz2
portato-77fa3af6a811e95ca7a9704e804ed22b5928aba5.zip
Always print debug messages in the file log
Diffstat (limited to 'portato/log.py')
-rw-r--r--portato/log.py17
1 files changed, 13 insertions, 4 deletions
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)