first commit
This commit is contained in:
BIN
app/utils/__pycache__/image_util.cpython-310.pyc
Normal file
BIN
app/utils/__pycache__/image_util.cpython-310.pyc
Normal file
Binary file not shown.
BIN
app/utils/__pycache__/image_util.cpython-311.pyc
Normal file
BIN
app/utils/__pycache__/image_util.cpython-311.pyc
Normal file
Binary file not shown.
BIN
app/utils/__pycache__/logger_util.cpython-310.pyc
Normal file
BIN
app/utils/__pycache__/logger_util.cpython-310.pyc
Normal file
Binary file not shown.
BIN
app/utils/__pycache__/logger_util.cpython-311.pyc
Normal file
BIN
app/utils/__pycache__/logger_util.cpython-311.pyc
Normal file
Binary file not shown.
BIN
app/utils/__pycache__/response_util.cpython-310.pyc
Normal file
BIN
app/utils/__pycache__/response_util.cpython-310.pyc
Normal file
Binary file not shown.
BIN
app/utils/__pycache__/response_util.cpython-311.pyc
Normal file
BIN
app/utils/__pycache__/response_util.cpython-311.pyc
Normal file
Binary file not shown.
BIN
app/utils/__pycache__/text_util.cpython-310.pyc
Normal file
BIN
app/utils/__pycache__/text_util.cpython-310.pyc
Normal file
Binary file not shown.
BIN
app/utils/__pycache__/text_util.cpython-311.pyc
Normal file
BIN
app/utils/__pycache__/text_util.cpython-311.pyc
Normal file
Binary file not shown.
BIN
app/utils/__pycache__/usage_util.cpython-310.pyc
Normal file
BIN
app/utils/__pycache__/usage_util.cpython-310.pyc
Normal file
Binary file not shown.
BIN
app/utils/__pycache__/usage_util.cpython-311.pyc
Normal file
BIN
app/utils/__pycache__/usage_util.cpython-311.pyc
Normal file
Binary file not shown.
BIN
app/utils/__pycache__/weaviate.cpython-310.pyc
Normal file
BIN
app/utils/__pycache__/weaviate.cpython-310.pyc
Normal file
Binary file not shown.
BIN
app/utils/__pycache__/weaviate_util.cpython-310.pyc
Normal file
BIN
app/utils/__pycache__/weaviate_util.cpython-310.pyc
Normal file
Binary file not shown.
25
app/utils/logger_util.py
Normal file
25
app/utils/logger_util.py
Normal file
@ -0,0 +1,25 @@
|
||||
import colorlog
|
||||
import sys
|
||||
import json
|
||||
|
||||
logger = colorlog.getLogger(__name__)
|
||||
logger.setLevel(colorlog.DEBUG)
|
||||
formatter = colorlog.ColoredFormatter(
|
||||
"%(log_color)s%(levelname)-8s%(reset)s %(purple)s%(message)s",
|
||||
datefmt=None,
|
||||
reset=True,
|
||||
log_colors={
|
||||
'DEBUG': 'cyan',
|
||||
'INFO': 'green',
|
||||
'WARNING': 'yellow',
|
||||
'ERROR': 'red',
|
||||
'CRITICAL': 'red',
|
||||
}
|
||||
)
|
||||
|
||||
stream_handler = colorlog.StreamHandler(sys.stdout)
|
||||
stream_handler.setFormatter(formatter)
|
||||
|
||||
logger.addHandler(stream_handler)
|
||||
|
||||
logger.json = lambda text: logger.debug(json.dumps(text, indent=4, sort_keys=True, default=str))
|
||||
15
app/utils/response_util.py
Normal file
15
app/utils/response_util.py
Normal file
@ -0,0 +1,15 @@
|
||||
import time
|
||||
from fastapi.responses import JSONResponse
|
||||
from app.utils.logger_util import logger
|
||||
|
||||
|
||||
def response(data: dict, start_time: float, code: int = 200) -> dict:
|
||||
speed = time.time() - start_time
|
||||
data["duration"] = speed
|
||||
|
||||
logger.debug(f"RESPONSE TIME: {speed}s")
|
||||
|
||||
if code != 200:
|
||||
return JSONResponse(content=data, status_code=code)
|
||||
|
||||
return data
|
||||
Reference in New Issue
Block a user