diff options
author | MaZderMind <github@mazdermind.de> | 2016-01-13 13:16:07 +0100 |
---|---|---|
committer | MaZderMind <github@mazdermind.de> | 2016-01-13 13:16:07 +0100 |
commit | 0cb0f1f16320c4b0314c5b81c91f022330e74642 (patch) | |
tree | e1e03aca23ae3a7d499113494a8bbde79a4e2c82 /voctogui | |
parent | 603bace75192efd80e0facc5454af5f1fd3651a3 (diff) |
port timestmap logging to gui
Diffstat (limited to 'voctogui')
-rw-r--r-- | voctogui/lib/args.py | 3 | ||||
-rw-r--r-- | voctogui/lib/loghandler.py | 15 | ||||
-rwxr-xr-x | voctogui/voctogui.py | 2 |
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: |