使用sanic自带的日志
使用的是sanic自带的日志记录
from sanic.log import * import logging from sanic import response from sanic.exceptions import * # 指定日志的文件名字,记录的日志记录在那个文件中 logging.basicConfig(filename="access.log") app = Sanic(__name__, configure_logging=LOGGING_CONFIG_DEFAULTS) @app.exception(SanicException) async def err404(request, exception): error_logger.warning("URI calledMy: {0} {1}".format(request.url,exception)) return response.json({"code": exception.status_code, "messages": exception.args[0]}) @app.exception(ServerError) async def ignore_sanic_5001(request, exception): error_logger.warning() return response.json({"code": exception.status_code, "messages": exception.args[0]}) @app.middleware("request") async def log_uri(request): # Simple middleware to log the URI endpoint that was called logger.info("URI calleds: {0}".format(request.url))