Sink logs to logs file

This commit is contained in:
Nestor Qin
2025-03-11 20:07:02 -07:00
parent aecb4ffa35
commit 8676682e97
2 changed files with 14 additions and 0 deletions

1
.gitignore vendored
View File

@@ -3,6 +3,7 @@ data1/
mongodb/
NapCat.Framework.Windows.Once/
log/
logs/
/test
/src/test
message_queue_content.txt

13
bot.py
View File

@@ -17,6 +17,19 @@ env_mask = {key: os.getenv(key) for key in os.environ}
uvicorn_server = None
# 配置日志
log_path = os.path.join(os.getcwd(), "logs")
if not os.path.exists(log_path):
os.makedirs(log_path)
# 添加文件日志启用rotation和retention
logger.add(
os.path.join(log_path, "maimbot_{time:YYYY-MM-DD}.log"),
rotation="00:00", # 每天0点创建新文件
retention="30 days", # 保留30天的日志
level="INFO",
encoding="utf-8"
)
def easter_egg():
# 彩蛋