log management update 03
This commit is contained in:
parent
02b6c8f24d
commit
5a2985e628
|
@ -6,7 +6,12 @@
|
|||
.ipynb_checkpoints
|
||||
__pycache__
|
||||
/utils/__pycache__
|
||||
|
||||
# 日志格式
|
||||
*.log
|
||||
*.txt
|
||||
*.csv
|
||||
*.data
|
||||
|
||||
|
||||
test.py
|
||||
|
|
15
utils/log.py
15
utils/log.py
|
@ -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) # 日志写入
|
||||
|
|
Loading…
Reference in New Issue