Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Commit

Permalink
新增 log记录文件。
Browse files Browse the repository at this point in the history
  • Loading branch information
yeying-xingchen committed Apr 5, 2024
1 parent f12a0f8 commit 2b8fd7d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 7 additions & 0 deletions example/log/2024-04-06.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[2024-04-06 01:12:27][INFO]欢迎使用 TodayDiscourse 今日话语
[2024-04-06 01:12:27][INFO]开发团队: XingchenOpenSource 星辰开源
[2024-04-06 01:12:27][INFO]项目地址: https://github.com/XingchenOpenSource/TodayDiscourse
[2024-04-06 01:12:27][INFO]官方文档: https://xingchenopensource.github.io/apis/todaydiscourse/
[2024-04-06 01:12:27][INFO]🎉恭喜您!今日话语已在 http://localhost:8080 上启动,请参阅官方文档以查看如何调用。
[2024-04-06 01:12:58][INFO]请求IP: 127.0.0.1 请求内容: 错误!调用方式错误!
[2024-04-06 01:13:03][INFO]请求IP: 127.0.0.1 请求内容: JSON
8 changes: 7 additions & 1 deletion todaydiscourse/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ def info(log):
current_time = datetime.datetime.now()
formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S")
print("\033[94m[" + formatted_time + "]\033[0m\033[92m[INFO]\033[0m" + log)
with open("./log/"+current_time.strftime("%Y-%m-%d") + '.log', 'a') as f:
f.write("[" + formatted_time + "][INFO]" + log + "\n")

def warning(log):
current_time = datetime.datetime.now()
formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S")
print("\033[94m[" + formatted_time + "]\033[0m\033[91m[WARN]\033[0m" + log)
with open("./log/"+current_time.strftime("%Y-%m-%d") + '.log', 'a') as f:
f.write("[" + formatted_time + "][WARN]" + log + "\n")

def error(log):
current_time = datetime.datetime.now()
formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S")
print("\033[94m[" + formatted_time + "]\033[0m\033[31m[ERROR]\033[0m" + log)
print("\033[94m[" + formatted_time + "]\033[0m\033[31m[ERROR]\033[0m" + log)
with open("./log/"+current_time.strftime("%Y-%m-%d") + '.log', 'a') as f:
f.write("[" + formatted_time + "][ERROR]" + log + "\n")

0 comments on commit 2b8fd7d

Please sign in to comment.