Closes #35: Implemented logging

This commit is contained in:
Sumner Evans
2020-01-20 14:33:54 -07:00
parent 07f8d81509
commit 072a8319b4
8 changed files with 100 additions and 43 deletions

View File

@@ -1,13 +1,50 @@
#! /usr/bin/env python3
import sys
import argparse
import logging
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk # noqa: F401
import sublime
from .app import SublimeMusicApp
def main():
parser = argparse.ArgumentParser(description='Sublime Music')
parser.add_argument(
'-v',
'--version',
help='show version and exit',
action='store_true',
)
parser.add_argument(
'-l',
'--logfile',
help='the filename to send logs to',
)
parser.add_argument(
'-m',
'--loglevel',
help='the minium level of logging to do',
default='WARNING',
)
args, unknown_args = parser.parse_known_args()
if args.version:
print(f'Sublime Music v{sublime.__version__}')
return
min_log_level = getattr(logging, args.loglevel.upper(), None)
if not isinstance(min_log_level, int):
logging.error(f'Invalid log level: {args.loglevel.upper()}.')
min_log_level = logging.WARNING
logging.basicConfig(
filename=args.logfile,
level=min_log_level,
format='%(asctime)s:%(levelname)s:%(name)s:%(module)s:%(message)s',
)
app = SublimeMusicApp()
app.run(sys.argv)
app.run(unknown_args)