opencv_webcam/utils/log.py

22 lines
696 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# OpenCV Webcam Script v0.3
# 创建人:曾逸夫
# 创建时间2022-01-14
import sys
# 日志管理
def log_management(logContent, logName, logSaveMode):
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) # 日志写入