summaryrefslogtreecommitdiff
path: root/voctogui/lib
diff options
context:
space:
mode:
Diffstat (limited to 'voctogui/lib')
-rw-r--r--voctogui/lib/args.py3
-rw-r--r--voctogui/lib/loghandler.py15
2 files changed, 14 insertions, 4 deletions
diff --git a/voctogui/lib/args.py b/voctogui/lib/args.py
index 6a34a6b..63e12d3 100644
--- a/voctogui/lib/args.py
+++ b/voctogui/lib/args.py
@@ -10,6 +10,9 @@ parser.add_argument('-v', '--verbose', action='count', default=0,
parser.add_argument('-c', '--color', action='store', choices=['auto', 'always', 'never'], default='auto',
help="Control the use of colors in the Log-Output")
+parser.add_argument('-t', '--timestamp', action='store_true',
+ help="Enable timestamps in the Log-Output")
+
parser.add_argument('-i', '--ini-file', action='store',
help="Load a custom config.ini-File")
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))