mirror of
https://github.com/StuffAnThings/qbit_manage.git
synced 2025-09-12 08:04:35 +08:00
better handling trace logs
This commit is contained in:
parent
7701a8fe0e
commit
c0b19bbc2d
5 changed files with 21 additions and 17 deletions
|
@ -18,11 +18,11 @@ class BeyondHD:
|
|||
def search(self, json, path="torrents/"):
|
||||
url = f"{base_url}{path}{self.apikey}"
|
||||
json["action"] = "search"
|
||||
if self.config.trace_mode:
|
||||
logger.debug(url)
|
||||
logger.debug(f"JSON: {json}")
|
||||
logger.trace(url)
|
||||
logger.trace(f"JSON: {json}")
|
||||
try:
|
||||
response = self.config.post(url, json=json)
|
||||
response = self.config.post(url, json=json, headers={"User-Agent": "Chrome"})
|
||||
logger.trace(response)
|
||||
response_json = response.json()
|
||||
except JSONDecodeError as e:
|
||||
if response.status_code >= 400:
|
||||
|
|
|
@ -38,8 +38,6 @@ class Config:
|
|||
|
||||
self.util = check(self)
|
||||
self.default_dir = default_dir
|
||||
self.test_mode = args["test"] if "test" in args else False
|
||||
self.trace_mode = args["trace"] if "trace" in args else False
|
||||
self.start_time = args["time_obj"]
|
||||
|
||||
loaded_yaml = YAML(self.config_path)
|
||||
|
|
|
@ -16,6 +16,7 @@ WARN = WARNING
|
|||
DRYRUN = 25
|
||||
INFO = 20
|
||||
DEBUG = 10
|
||||
TRACE = 5
|
||||
|
||||
|
||||
def fmt_filter(record):
|
||||
|
@ -28,12 +29,11 @@ _srcfile = os.path.normcase(fmt_filter.__code__.co_filename)
|
|||
|
||||
|
||||
class MyLogger:
|
||||
def __init__(self, logger_name, log_file, log_level, default_dir, screen_width, separating_character, ignore_ghost, is_debug):
|
||||
def __init__(self, logger_name, log_file, log_level, default_dir, screen_width, separating_character, ignore_ghost):
|
||||
self.logger_name = logger_name
|
||||
self.default_dir = default_dir
|
||||
self.screen_width = screen_width
|
||||
self.separating_character = separating_character
|
||||
self.is_debug = is_debug
|
||||
self.ignore_ghost = ignore_ghost
|
||||
self.log_dir = os.path.join(default_dir, LOG_DIR)
|
||||
self.main_log = log_file if os.path.exists(os.path.dirname(log_file)) else os.path.join(self.log_dir, log_file)
|
||||
|
@ -48,6 +48,9 @@ class MyLogger:
|
|||
logging.DRYRUN = DRYRUN
|
||||
logging.addLevelName(DRYRUN, "DRYRUN")
|
||||
setattr(self._logger, "dryrun", lambda dryrun, *args: self._logger._log(DRYRUN, dryrun, args))
|
||||
logging.TRACE = TRACE
|
||||
logging.addLevelName(TRACE, "TRACE")
|
||||
setattr(self._logger, "trace", lambda trace, *args: self._logger._log(TRACE, trace, args))
|
||||
self._log_level = getattr(logging, log_level.upper())
|
||||
self._logger.setLevel(self._log_level)
|
||||
|
||||
|
@ -127,6 +130,10 @@ class MyLogger:
|
|||
self._log(loglvl, str(msg), args, **kwargs)
|
||||
return [str(msg)]
|
||||
|
||||
def trace(self, msg, *args, **kwargs):
|
||||
if self._logger.isEnabledFor(TRACE):
|
||||
self._log(TRACE, str(msg), args, **kwargs)
|
||||
|
||||
def debug(self, msg, *args, **kwargs):
|
||||
if self._logger.isEnabledFor(DEBUG):
|
||||
self._log(DEBUG, str(msg), args, **kwargs)
|
||||
|
|
|
@ -23,13 +23,11 @@ class Webhooks:
|
|||
self.apprise = apprise
|
||||
|
||||
def _request(self, webhooks, json):
|
||||
if self.config.trace_mode:
|
||||
logger.debug("")
|
||||
logger.debug(f"JSON: {json}")
|
||||
logger.trace("")
|
||||
logger.trace(f"JSON: {json}")
|
||||
for webhook in list(set(webhooks)):
|
||||
response = None
|
||||
if self.config.trace_mode:
|
||||
logger.debug(f"Webhook: {webhook}")
|
||||
logger.trace(f"Webhook: {webhook}")
|
||||
if webhook is None:
|
||||
break
|
||||
elif webhook == "notifiarr":
|
||||
|
@ -56,8 +54,7 @@ class Webhooks:
|
|||
skip = False
|
||||
try:
|
||||
response_json = response.json()
|
||||
if self.config.trace_mode:
|
||||
logger.debug(f"Response: {response_json}")
|
||||
logger.trace(f"Response: {response_json}")
|
||||
if (
|
||||
"result" in response_json
|
||||
and response_json["result"] == "error"
|
||||
|
|
|
@ -207,8 +207,10 @@ screen_width = get_arg("QBT_WIDTH", args.width, arg_int=True)
|
|||
debug = get_arg("QBT_DEBUG", args.debug, arg_bool=True)
|
||||
trace = get_arg("QBT_TRACE", args.trace, arg_bool=True)
|
||||
|
||||
if debug or trace:
|
||||
if debug:
|
||||
log_level = "DEBUG"
|
||||
if trace:
|
||||
log_level = "TRACE"
|
||||
|
||||
stats = {}
|
||||
args = {}
|
||||
|
@ -273,7 +275,7 @@ except ValueError:
|
|||
sys.exit(0)
|
||||
|
||||
|
||||
logger = MyLogger("qBit Manage", log_file, log_level, default_dir, screen_width, divider[0], False, debug or trace)
|
||||
logger = MyLogger("qBit Manage", log_file, log_level, default_dir, screen_width, divider[0], False)
|
||||
from modules import util # noqa
|
||||
|
||||
util.logger = logger
|
||||
|
|
Loading…
Add table
Reference in a new issue