log management update 03

This commit is contained in:
13339479676 2022-01-14 20:17:30 +08:00
parent 02b6c8f24d
commit 5a2985e628
2 changed files with 17 additions and 3 deletions

5
.gitignore vendored
View File

@ -6,7 +6,12 @@
.ipynb_checkpoints
__pycache__
/utils/__pycache__
# 日志格式
*.log
*.txt
*.csv
*.data
test.py

View File

@ -7,6 +7,15 @@ import sys
# 日志管理
def log_management(logContent, logName, logSaveMode):
ROOT_PATH = sys.path[0]
logFile = open(f'{ROOT_PATH}/{logName}', logSaveMode)
logFile.write(logContent)
suffixList = ['log', 'txt', 'data'] # 日志后缀列表
logSuffixFlag = 0 # 日志后缀标志
for i in range(len(suffixList)):
# 查找日志后缀
if logName.endswith(suffixList[i]):
logSuffixFlag = 1
if logSuffixFlag == 0:
print(f'日志格式不正确!程序结束!')
sys.exit() # 结束程序
ROOT_PATH = sys.path[0] # 项目根目录
logFile = open(f'{ROOT_PATH}/{logName}', logSaveMode) # 日志文件
logFile.write(logContent) # 日志写入