mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 15:37:35 +08:00
change: replace logging with loguru
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
import contextlib
|
import contextlib
|
||||||
import logging
|
|
||||||
import sys
|
import sys
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
|
|
||||||
from fastapi import APIRouter
|
from fastapi import APIRouter
|
||||||
|
from loguru import logger
|
||||||
from starlette.requests import Request
|
from starlette.requests import Request
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
@@ -37,6 +37,6 @@ async def debug_python(request: Request):
|
|||||||
resp["code"] = 1
|
resp["code"] = 1
|
||||||
resp["message"] = "fail"
|
resp["message"] = "fail"
|
||||||
resp["result"] = str(ex)
|
resp["result"] = str(ex)
|
||||||
logging.error(resp)
|
logger.error(resp)
|
||||||
|
|
||||||
return resp
|
return resp
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import logging
|
|
||||||
import subprocess
|
import subprocess
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
from fastapi import APIRouter
|
from fastapi import APIRouter
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@@ -29,6 +29,6 @@ async def install_dependenies(deps: List[str]):
|
|||||||
resp["result"][dep] = False
|
resp["result"][dep] = False
|
||||||
resp["code"] = 1
|
resp["code"] = 1
|
||||||
resp["message"] = "fail"
|
resp["message"] = "fail"
|
||||||
logging.error(f"failed to install dependency: {dep}")
|
logger.error(f"failed to install dependency: {dep}")
|
||||||
|
|
||||||
return resp
|
return resp
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import io
|
import io
|
||||||
import json
|
import json
|
||||||
import logging
|
|
||||||
import sys
|
import sys
|
||||||
from json.decoder import JSONDecodeError
|
from json.decoder import JSONDecodeError
|
||||||
from urllib.parse import unquote
|
from urllib.parse import unquote
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
|
|
||||||
def load_har_log_entries(file_path):
|
def load_har_log_entries(file_path):
|
||||||
@@ -33,7 +33,7 @@ def load_har_log_entries(file_path):
|
|||||||
content_json = json.loads(f.read())
|
content_json = json.loads(f.read())
|
||||||
return content_json["log"]["entries"]
|
return content_json["log"]["entries"]
|
||||||
except (KeyError, TypeError, JSONDecodeError):
|
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)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
@@ -103,20 +103,20 @@ def convert_list_to_dict(origin_list):
|
|||||||
def dump_yaml(testcase, yaml_file):
|
def dump_yaml(testcase, yaml_file):
|
||||||
""" dump HAR entries to yaml testcase
|
""" 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:
|
with io.open(yaml_file, "w", encoding="utf-8") as outfile:
|
||||||
yaml.dump(
|
yaml.dump(
|
||||||
testcase, outfile, allow_unicode=True, default_flow_style=False, indent=4
|
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):
|
def dump_json(testcase, json_file):
|
||||||
""" dump HAR entries to json testcase
|
""" 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:
|
with io.open(json_file, "w", encoding="utf-8") as outfile:
|
||||||
my_json_str = json.dumps(testcase, ensure_ascii=False, indent=4)
|
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)
|
outfile.write(my_json_str)
|
||||||
|
|
||||||
logging.info("Generate JSON testcase successfully: {}".format(json_file))
|
logger.info("Generate JSON testcase successfully: {}".format(json_file))
|
||||||
|
|||||||
Reference in New Issue
Block a user