change: replace logging with loguru

This commit is contained in:
debugtalk
2020-06-04 11:24:47 +08:00
parent 5b245fec0d
commit 73bbf32512
3 changed files with 10 additions and 10 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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))