more logging
This commit is contained in:
parent
b162f63ab2
commit
a9f52351e7
19
main.py
19
main.py
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
from functools import partial, partialmethod
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import argparse
|
import argparse
|
||||||
import json
|
import json
|
||||||
@ -12,10 +13,17 @@ import sys
|
|||||||
import typing as t
|
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):
|
class LogFormatter(logging.Formatter):
|
||||||
|
|
||||||
format = "%(name)s [%(levelname)s] %(message)s"
|
format = "%(name)s [%(levelname)s] %(message)s"
|
||||||
FORMATS = {
|
FORMATS = {
|
||||||
|
logging.TRACE: f"\x1b[30;20m{format}\x1b[0m",
|
||||||
logging.DEBUG: f"\x1b[38;20m{format}\x1b[0m",
|
logging.DEBUG: f"\x1b[38;20m{format}\x1b[0m",
|
||||||
logging.INFO: f"\x1b[34;20m{format}\x1b[0m",
|
logging.INFO: f"\x1b[34;20m{format}\x1b[0m",
|
||||||
logging.WARNING: f"\x1b[33;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:
|
if not chunks:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
LOG.trace(line)
|
||||||
|
|
||||||
match chunks:
|
match chunks:
|
||||||
case ["player", id, username, *rest]:
|
case ["player", id, username, *rest]:
|
||||||
players[id] = username
|
players[id] = username
|
||||||
@ -247,14 +257,15 @@ def main():
|
|||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
prog=APP, description="extracts stats from a Showdown replay"
|
prog=APP, description="extracts stats from a Showdown replay"
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument("-v", "--verbose", action="count", help="add debugging info")
|
||||||
"-v", "--verbose", action="store_true", help="add debugging info"
|
|
||||||
)
|
|
||||||
parser.add_argument("-c", "--cache", action="store_true", help="cache replays")
|
parser.add_argument("-c", "--cache", action="store_true", help="cache replays")
|
||||||
parser.add_argument("replay", nargs="+", help="replay ID or URL")
|
parser.add_argument("replay", nargs="+", help="replay ID or URL")
|
||||||
|
|
||||||
args = parser.parse_args(sys.argv[1:])
|
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:
|
try:
|
||||||
db = sqlite3.connect("data.db")
|
db = sqlite3.connect("data.db")
|
||||||
|
Loading…
Reference in New Issue
Block a user