This commit is contained in:
harry
2024-03-11 16:37:49 +08:00
parent d4f7b53b84
commit 06df797234
71 changed files with 2725 additions and 1 deletions

51
app/config/__init__.py Normal file
View File

@@ -0,0 +1,51 @@
import os
import sys
from loguru import logger
from app.config import config
from app.utils import utils
def __init_logger():
_log_file = utils.storage_dir("logs/server.log")
_lvl = config.log_level
root_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
def format_record(record):
# 获取日志记录中的文件全路径
file_path = record["file"].path
# 将绝对路径转换为相对于项目根目录的路径
relative_path = os.path.relpath(file_path, root_dir)
# 更新记录中的文件路径
record["file"].path = f"./{relative_path}"
# 返回修改后的格式字符串
# 您可以根据需要调整这里的格式
_format = '<green>{time:%Y-%m-%d %H:%M:%S}</> | ' + \
'<level>{level}</> | ' + \
'"{file.path}:{line}":<blue> {function}</> ' + \
'- <level>{message}</>' + "\n"
return _format
logger.remove()
logger.add(
sys.stdout,
level=_lvl,
format=format_record,
colorize=True,
)
logger.add(
_log_file,
level=_lvl,
format=format_record,
rotation="00:00",
retention="3 days",
backtrace=True,
diagnose=True,
enqueue=True,
)
__init_logger()

31
app/config/config.py Normal file
View File

@@ -0,0 +1,31 @@
import os
import tomli
from loguru import logger
root_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
config_file = f"{root_dir}/config.toml"
logger.info(f"load config from file: {config_file}")
with open(config_file, mode="rb") as fp:
_cfg = tomli.load(fp)
app = _cfg.get("app", {})
whisper = _cfg.get("whisper", {})
hostname = os.uname().nodename
log_level = _cfg.get("log_level", "DEBUG")
listen_host = _cfg.get("listen_host", "0.0.0.0")
listen_port = _cfg.get("listen_port", 8080)
project_name = _cfg.get("project_name", "MoneyPrinterTurbo")
project_description = _cfg.get("project_description", "MoneyPrinterTurbo\n by 抖音-网旭哈瑞.AI")
project_version = _cfg.get("project_version", "1.0.0")
reload_debug = False
__cfg = {
"hostname": hostname,
"listen_host": listen_host,
"listen_port": listen_port,
}
logger.info(__cfg)