aboutsummaryrefslogtreecommitdiff
path: root/voctogui/lib/loghandler.py
diff options
context:
space:
mode:
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))