From dbf016cf4355fbf171c856be3bea5a38f7a9f72d Mon Sep 17 00:00:00 2001 From: Manuel Koch Date: Fri, 6 Apr 2018 16:28:15 +0200 Subject: [PATCH] At commandline option to log with timestamps and logger info --- gitover/main.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/gitover/main.py b/gitover/main.py index 51cfc21..6027832 100644 --- a/gitover/main.py +++ b/gitover/main.py @@ -48,20 +48,22 @@ def exception_hook(exctype, value, traceback): # End of PyQt5 hack -def setupLogging(verbose, path=None): +def setupLogging(verbose, detailed=False, path=None): "Setup logging functionality" rootlogger = logging.getLogger() hdl = logging.StreamHandler(sys.stdout) + fmtmsg = "%(asctime)s %(levelname)s %(name)s(%(lineno)d): %(message)s" if verbose: hdl.setLevel(logging.DEBUG) else: hdl.setLevel(logging.INFO) + if detailed: + hdl.setFormatter(logging.Formatter(fmtmsg)) rootlogger.addHandler(hdl) if path: fhdl = logging.FileHandler(path, mode="w", encoding="utf-8") fhdl.setLevel(logging.DEBUG) - fhdl.setFormatter( - logging.Formatter("%(asctime)s %(levelname)s %(pathname)s(%(lineno)d): %(message)s")) + fhdl.setFormatter(logging.Formatter(fmtmsg)) rootlogger.addHandler(fhdl) rootlogger.setLevel(logging.DEBUG) @@ -73,14 +75,16 @@ def main(): grpMisc = parser.add_argument_group('Misc') grpMisc.add_argument('--version', action='version', version='%(prog)s') grpMisc.add_argument('--verbose', dest='verbose', action="store_true", - help='Be more verbose on console.') + help='Be more verbose on console logging.') + grpMisc.add_argument('--timing', dest='timing', action="store_true", + help='Include timestamps on console logging.') grpMisc.add_argument('--log', dest='logPath', metavar="PATH", help='Store verbose messages during processing in given file too.') grpMisc.add_argument('--no-fs-watch', dest='watchFs', action="store_false", default=True, help="Don't watch filesystem changes in repositories.") args = parser.parse_args() - setupLogging(args.verbose, args.logPath) + setupLogging(args.verbose, args.timing, args.logPath) if sys.platform == "win32": # The default SIGBREAK action remains to call Win32 ExitProcess().