我想监视日志文件,直到使用Jython在文件中找到特定字符串为止
示例代码:
import codecs
import sys
import time
cnt = True
while cnt:
if 'User TechAdmin is logged out' in open('<File path>/Log_File_Test.log').read():
if 'ERROR' in open('<File path>/Log_File_Test.log').read():
raise StandardError ("Error Found in File - Please refer log")
else:
read_f = ''
cnt = False
else:
time.sleep(3)
代码应监视文件,直到找到“ User TechAdmin注销”为止。如果找到,那么我想检查文件中是否存在字符串“ Error”。如果发现错误,请引发异常并关闭文件。