因此,我在 python 文件(main.py)中编写了程序,该文件使用 api 包装文件(bluerev.py)中的类。我想使用 main.py 中的 loguru 记录器来收集程序中的所有异常 + api 包装器中发出的所有请求。因此,bluerev.py api 包装器中设置的日志记录如下所示:
import logging
#Logging setup
logger = logging.getLogger(__name__)
logger.addHandler(logging.NullHandler())
class BluerevApiRequestHandler:
def __init__(self):
self.date_str_format = "%Y-%m-%dT%H:%M:%S.%f"
@staticmethod
def setup_logger_for_requests():
"""
Sets up the requests library to log api requests
"""
logger.setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True
Run Code Online (Sandbox Code Playgroud)
main.py 日志记录代码如下所示:
from blurev import *
from loguru import logger
#more imports and code
@logger.catch
def main():
# associated file and credential locations
gmail_creds_file = "gmail_creds.json"
revu_creds_file = r"revu_credentials.json" …Run Code Online (Sandbox Code Playgroud)