aboutsummaryrefslogtreecommitdiff
path: root/voctogui/lib/loghandler.py
diff options
context:
space:
mode:
authorMaZderMind <github@mazdermind.de>2016-01-13 13:16:07 +0100
committerMaZderMind <github@mazdermind.de>2016-01-13 13:16:07 +0100
commit0cb0f1f16320c4b0314c5b81c91f022330e74642 (patch)
treee1e03aca23ae3a7d499113494a8bbde79a4e2c82 /voctogui/lib/loghandler.py
parent603bace75192efd80e0facc5454af5f1fd3651a3 (diff)
port timestmap logging to gui
Diffstat (limited to 'voctogui/lib/loghandler.py')
-rw-r--r--voctogui/lib/loghandler.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/voctogui/lib/loghandler.py b/voctogui/lib/loghandler.py
index 4e48c7d..f0a60ee 100644
--- a/voctogui/lib/loghandler.py
+++ b/voctogui/lib/loghandler.py
@@ -1,10 +1,11 @@
#!/usr/bin/python3
-import logging
+import logging, time
class LogFormatter(logging.Formatter):
- def __init__(self, docolor):
+ def __init__(self, docolor, timestamps=False):
super().__init__()
self.docolor = docolor
+ self.timestamps = timestamps
def formatMessage(self, record):
if self.docolor:
@@ -26,10 +27,16 @@ class LogFormatter(logging.Formatter):
else:
fmt = '%(levelname)8s %(name)s: %(message)s'
+ if self.timestamps:
+ fmt = '%(asctime)s '+fmt
+
+ if not 'asctime' in record.__dict__:
+ record.__dict__['asctime']=time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(record.__dict__['created']))
+
return fmt % record.__dict__
class LogHandler(logging.StreamHandler):
- def __init__(self, docolor):
+ def __init__(self, docolor, timestamps):
super().__init__()
- self.setFormatter(LogFormatter(docolor))
+ self.setFormatter(LogFormatter(docolor,timestamps))