diff --git a/httprunner/app/routers/debugtalk.py b/httprunner/app/routers/debugtalk.py index bdb9a6b9..eec92599 100644 --- a/httprunner/app/routers/debugtalk.py +++ b/httprunner/app/routers/debugtalk.py @@ -1,9 +1,9 @@ import contextlib -import logging import sys from io import StringIO from fastapi import APIRouter +from loguru import logger from starlette.requests import Request router = APIRouter() @@ -37,6 +37,6 @@ async def debug_python(request: Request): resp["code"] = 1 resp["message"] = "fail" resp["result"] = str(ex) - logging.error(resp) + logger.error(resp) return resp diff --git a/httprunner/app/routers/deps.py b/httprunner/app/routers/deps.py index 70e0a017..b83ec3ee 100644 --- a/httprunner/app/routers/deps.py +++ b/httprunner/app/routers/deps.py @@ -1,9 +1,9 @@ -import logging import subprocess from typing import List import pkg_resources from fastapi import APIRouter +from loguru import logger router = APIRouter() @@ -29,6 +29,6 @@ async def install_dependenies(deps: List[str]): resp["result"][dep] = False resp["code"] = 1 resp["message"] = "fail" - logging.error(f"failed to install dependency: {dep}") + logger.error(f"failed to install dependency: {dep}") return resp diff --git a/httprunner/ext/har2case/utils.py b/httprunner/ext/har2case/utils.py index f2fdd852..63b93530 100644 --- a/httprunner/ext/har2case/utils.py +++ b/httprunner/ext/har2case/utils.py @@ -1,11 +1,11 @@ import io import json -import logging import sys from json.decoder import JSONDecodeError from urllib.parse import unquote import yaml +from loguru import logger def load_har_log_entries(file_path): @@ -33,7 +33,7 @@ def load_har_log_entries(file_path): content_json = json.loads(f.read()) return content_json["log"]["entries"] except (KeyError, TypeError, JSONDecodeError): - logging.error("HAR file content error: {}".format(file_path)) + logger.error("HAR file content error: {}".format(file_path)) sys.exit(1) @@ -103,20 +103,20 @@ def convert_list_to_dict(origin_list): def dump_yaml(testcase, yaml_file): """ dump HAR entries to yaml testcase """ - logging.info("dump testcase to YAML format.") + logger.info("dump testcase to YAML format.") with io.open(yaml_file, "w", encoding="utf-8") as outfile: yaml.dump( testcase, outfile, allow_unicode=True, default_flow_style=False, indent=4 ) - logging.info("Generate YAML testcase successfully: {}".format(yaml_file)) + logger.info("Generate YAML testcase successfully: {}".format(yaml_file)) def dump_json(testcase, json_file): """ dump HAR entries to json testcase """ - logging.info("dump testcase to JSON format.") + logger.info("dump testcase to JSON format.") with io.open(json_file, "w", encoding="utf-8") as outfile: my_json_str = json.dumps(testcase, ensure_ascii=False, indent=4) @@ -125,4 +125,4 @@ def dump_json(testcase, json_file): outfile.write(my_json_str) - logging.info("Generate JSON testcase successfully: {}".format(json_file)) + logger.info("Generate JSON testcase successfully: {}".format(json_file))