Setup coloredlogs

This commit is contained in:
Ritiek Malhotra
2020-05-03 09:06:03 +05:30
parent 715a95df1e
commit ec765119fa
13 changed files with 101 additions and 83 deletions

View File

@@ -1,16 +1,37 @@
import logzero
import logging
for module in ("urllib3", "spotipy", "pytube",):
logging.getLogger(module).setLevel(logging.CRITICAL)
import coloredlogs
coloredlogs.DEFAULT_FIELD_STYLES = {
"levelname": {"bold": True, "color": "yellow"},
"name": {"color": "blue"},
"lineno": {"color": "magenta"},
}
import sys
from spotdl import command_line
def set_logger(level):
if level == logging.DEBUG:
fmt = "%(levelname)s:%(name)s:%(lineno)d:\n%(message)s"
else:
fmt = "%(levelname)s: %(message)s"
logging.basicConfig(format=fmt, level=level)
logger = logging.getLogger(name=__name__)
coloredlogs.install(level=level, fmt=fmt, logger=logger)
return logger
def main():
arguments = command_line.get_arguments()
spotdl = command_line.Spotdl(arguments.__dict__)
from spotdl.command_line.arguments import get_arguments
arguments = get_arguments()
logger = set_logger(arguments["log_level"])
from spotdl.command_line.lib import Spotdl
spotdl = Spotdl(arguments)
try:
spotdl.match_arguments()
except KeyboardInterrupt as e:
logzero.logger.exception(e)
logger.exception(e)
sys.exit(2)