more logging

This commit is contained in:
xeals 2023-03-28 00:00:15 +11:00
parent b162f63ab2
commit a9f52351e7
Signed by: xeals
GPG Key ID: A498C7AF27EC6B5C

19
main.py
View File

@ -2,6 +2,7 @@
from collections import namedtuple
from dataclasses import dataclass
from functools import partial, partialmethod
from pathlib import Path
import argparse
import json
@ -12,10 +13,17 @@ import sys
import typing as t
logging.TRACE = 5
logging.addLevelName(logging.TRACE, "TRACE")
logging.Logger.trace = partialmethod(logging.Logger.log, logging.TRACE)
logging.trace = partial(logging.log, logging.TRACE)
class LogFormatter(logging.Formatter):
format = "%(name)s [%(levelname)s] %(message)s"
FORMATS = {
logging.TRACE: f"\x1b[30;20m{format}\x1b[0m",
logging.DEBUG: f"\x1b[38;20m{format}\x1b[0m",
logging.INFO: f"\x1b[34;20m{format}\x1b[0m",
logging.WARNING: f"\x1b[33;20m{format}\x1b[0m",
@ -108,6 +116,8 @@ def parse_log(game: str, log: str, into: sqlite3.Connection):
if not chunks:
continue
LOG.trace(line)
match chunks:
case ["player", id, username, *rest]:
players[id] = username
@ -247,14 +257,15 @@ def main():
parser = argparse.ArgumentParser(
prog=APP, description="extracts stats from a Showdown replay"
)
parser.add_argument(
"-v", "--verbose", action="store_true", help="add debugging info"
)
parser.add_argument("-v", "--verbose", action="count", help="add debugging info")
parser.add_argument("-c", "--cache", action="store_true", help="cache replays")
parser.add_argument("replay", nargs="+", help="replay ID or URL")
args = parser.parse_args(sys.argv[1:])
LOG.setLevel(logging.DEBUG if args.verbose else logging.INFO)
if args.verbose > 1:
LOG.setLevel(logging.TRACE)
elif args.verbose > 0:
LOG.setLevel(logging.DEBUG)
try:
db = sqlite3.connect("data.db")