import peter

This commit is contained in:
konjacpotato
2025-11-12 20:42:16 +08:00
commit 8c1a740f0b
147 changed files with 2763 additions and 0 deletions

0
log/__init__.py Normal file
View File

Binary file not shown.

Binary file not shown.

70
log/log_manager.py Normal file
View File

@ -0,0 +1,70 @@
import logging.config
import sys
import config.config
"""
Usage:
1 code
from log.log_manager import logger
logger.info("Starting Jarvas")
2 app start
python demo.py --logconfig=log_prod.config
当前目录下的log_prod.config是一份参考配置
"""
# default logging config for development
LOG_DEV_CONFIG = {
"version": 1,
"disable_existing_loggers": False,
"loggers": {
"root": {
"level": "INFO",
"handlers": ["consoleHandler"]
}
},
"handlers": {
"consoleHandler": {
"class": "logging.StreamHandler",
"level": "INFO",
"formatter": "verbose",
"stream": sys.stdout
}
},
"formatters": {
"verbose": {
"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s",
"datefmt": "%Y-%m-%d %H:%M:%S"
}
}
}
log_config_message = ""
# 获取命令行参数
args = sys.argv
# 查找包含 'logconfig' 的参数
logconfig_param = next((arg for arg in args if '--logconfig' in arg), None)
logconfig_value = None
if logconfig_param:
# 如果找到了 logconfig 参数,提取其值
_, logconfig_value = logconfig_param.split('=') # 以 '=' 分割
log_config_message = f"--logconfig value: {logconfig_value}"
else:
log_config_message = "没有找到 --logconfig 参数使用默认log配置"
if logconfig_value:
# 使用入参日志配置文件
logging.config.fileConfig(logconfig_value)
else:
# 使用默认日志配置
logging.config.dictConfig(LOG_DEV_CONFIG)
logger = logging.getLogger('root')
# 打印日志配置信息
logger.info(log_config_message)
def log(message: str):
logger.info(f'{config.config.scheduler_name} {message}')

22
log/log_prod.config Normal file
View File

@ -0,0 +1,22 @@
[loggers]
keys=root
[handlers]
keys=fileHandler
[formatters]
keys=verbose
[logger_root]
level=INFO
handlers=fileHandler
[handler_fileHandler]
class=FileHandler
level=INFO
formatter=verbose
args=('app.log', 'a')
[formatter_verbose]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
datefmt=%Y-%m-%d %H:%M:%S