Skip to content

Commit

Permalink
At commandline option to log with timestamps and logger info
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-koch committed Apr 6, 2018
1 parent f660bb9 commit dbf016c
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions gitover/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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().
Expand Down

0 comments on commit dbf016c

Please sign in to comment.