aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--voctogui/lib/args.py3
-rw-r--r--voctogui/lib/loghandler.py15
-rwxr-xr-xvoctogui/voctogui.py2
3 files changed, 15 insertions, 5 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))
diff --git a/voctogui/voctogui.py b/voctogui/voctogui.py
index 123a305..8bb444b 100755
--- a/voctogui/voctogui.py
+++ b/voctogui/voctogui.py
@@ -86,7 +86,7 @@ def main():
# configure logging
docolor = (Args.color == 'always') or (Args.color == 'auto' and sys.stderr.isatty())
- handler = LogHandler(docolor)
+ handler = LogHandler(docolor, Args.timestamp)
logging.root.addHandler(handler)
if Args.verbose >= 2: