Fix the logging options debug mode

This commit is contained in:
DevilXD committed 2021-12-17 13:10:51 +01:00
1 parent 09d33e3017
commit 3ac32009a0
1 file changed
+26 -17
+26 -17
View File
@@ -11,7 +11,7 @@ import argparse
import warnings import warnings
import traceback import traceback
import threading import threading
from typing import Literal, NoReturn from typing import NoReturn
from twitch import Twitch from twitch import Twitch
from constants import JsonType, SETTINGS_PATH, TERMINATED_STR from constants import JsonType, SETTINGS_PATH, TERMINATED_STR
@@ -44,8 +44,8 @@ def terminate() -> NoReturn:
class ParsedArgs(argparse.Namespace): class ParsedArgs(argparse.Namespace):
_verbose: int _verbose: int
debug_ws: Literal[Literal[0], Literal[10]] _debug_ws: bool
debug_gql: Literal[Literal[0], Literal[10]] _debug_gql: bool
@property @property
def logging_level(self) -> int: def logging_level(self) -> int:
@@ -56,6 +56,27 @@ class ParsedArgs(argparse.Namespace):
3: logging.DEBUG, 3: logging.DEBUG,
}.get(self._verbose, logging.DEBUG) }.get(self._verbose, logging.DEBUG)
@property
def debug_ws(self) -> int:
"""
If the debug flag is True, return DEBUG.
If the main logging level is DEBUG, return INFO to avoid seeing raw messages.
Otherwise, return NOTSET to inherit the global logging level.
"""
if self._debug_ws:
return logging.DEBUG
elif self._verbose >= 3:
return logging.INFO
return logging.NOTSET
@property
def debug_gql(self) -> int:
if self._debug_gql:
return logging.DEBUG
elif self._verbose >= 3:
return logging.INFO
return logging.NOTSET
# handle input parameters # handle input parameters
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
@@ -64,20 +85,8 @@ parser = argparse.ArgumentParser(
) )
parser.add_argument("-V", "--version", action="version", version=f"v{__version__}") parser.add_argument("-V", "--version", action="version", version=f"v{__version__}")
parser.add_argument("-v", dest="_verbose", action="count", default=0) parser.add_argument("-v", dest="_verbose", action="count", default=0)
parser.add_argument( parser.add_argument("--debug-ws", dest="_debug_ws", action="store_true")
"--debug-ws", parser.add_argument("--debug-gql", dest="_debug_gql", action="store_true")
dest="debug_ws",
action="store_const",
const=logging.DEBUG,
default=logging.NOTSET,
)
parser.add_argument(
"--debug-gql",
dest="debug_gql",
action="store_const",
const=logging.DEBUG,
default=logging.NOTSET,
)
options: ParsedArgs = parser.parse_args(namespace=ParsedArgs()) options: ParsedArgs = parser.parse_args(namespace=ParsedArgs())
# handle logging stuff # handle logging stuff
if options.logging_level > logging.DEBUG: if options.logging_level > logging.DEBUG: