mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-08-24 02:57:13 +00:00
feat: 分文件存储日志 (#190)
This commit is contained in:
+2
-1
@@ -8,4 +8,5 @@ config.py
|
|||||||
plugins/
|
plugins/
|
||||||
!plugins/__init__.py
|
!plugins/__init__.py
|
||||||
/revcfg.py
|
/revcfg.py
|
||||||
prompts/
|
prompts/
|
||||||
|
logs/
|
||||||
@@ -45,8 +45,28 @@ def init_db():
|
|||||||
|
|
||||||
known_exception_caught = False
|
known_exception_caught = False
|
||||||
|
|
||||||
|
log_file_name = "qchatgpt.log"
|
||||||
|
|
||||||
|
|
||||||
|
def init_runtime_log_file():
|
||||||
|
"""为此次运行生成日志文件
|
||||||
|
格式: qchatgpt-yyyy-MM-dd-HH-mm-ss.log
|
||||||
|
"""
|
||||||
|
global log_file_name
|
||||||
|
|
||||||
|
# 检查logs目录是否存在
|
||||||
|
if not os.path.exists("logs"):
|
||||||
|
os.mkdir("logs")
|
||||||
|
|
||||||
|
# 检查本目录是否有qchatgpt.log,若有,移动到logs目录
|
||||||
|
if os.path.exists("qchatgpt.log"):
|
||||||
|
shutil.move("qchatgpt.log", "logs/qchatgpt.legacy.log")
|
||||||
|
|
||||||
|
log_file_name = "logs/qchatgpt-%s.log" % time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())
|
||||||
|
|
||||||
|
|
||||||
def reset_logging():
|
def reset_logging():
|
||||||
|
global log_file_name
|
||||||
assert os.path.exists('config.py')
|
assert os.path.exists('config.py')
|
||||||
|
|
||||||
config = importlib.import_module('config')
|
config = importlib.import_module('config')
|
||||||
@@ -60,7 +80,7 @@ def reset_logging():
|
|||||||
logging.getLogger().removeHandler(handler)
|
logging.getLogger().removeHandler(handler)
|
||||||
|
|
||||||
logging.basicConfig(level=config.logging_level, # 设置日志输出格式
|
logging.basicConfig(level=config.logging_level, # 设置日志输出格式
|
||||||
filename='qchatgpt.log', # log日志输出的文件位置和文件名
|
filename=log_file_name, # log日志输出的文件位置和文件名
|
||||||
format="[%(asctime)s.%(msecs)03d] %(filename)s (%(lineno)d) - [%(levelname)s] : %(message)s",
|
format="[%(asctime)s.%(msecs)03d] %(filename)s (%(lineno)d) - [%(levelname)s] : %(message)s",
|
||||||
# 日志输出的格式
|
# 日志输出的格式
|
||||||
# -8表示占位符,让输出左对齐,输出长度都为8位
|
# -8表示占位符,让输出左对齐,输出长度都为8位
|
||||||
@@ -98,6 +118,8 @@ def main(first_time_init=False):
|
|||||||
import pkg.utils.context
|
import pkg.utils.context
|
||||||
pkg.utils.context.set_config(config)
|
pkg.utils.context.set_config(config)
|
||||||
|
|
||||||
|
init_runtime_log_file()
|
||||||
|
|
||||||
sh = reset_logging()
|
sh = reset_logging()
|
||||||
|
|
||||||
# 检查是否设置了管理员
|
# 检查是否设置了管理员
|
||||||
|
|||||||
Reference in New Issue
Block a user