使用python运行实时脚本时出错

时间:2017-10-19 13:31:12

标签: python

我有来自syslog服务器的file.log,我想根据列解析文件并放入不同的文件(parsing.log) 当我运行我的脚本时出现错误:

Traceback (most recent call last):
  File "coding/parsing.py", line 17, in <module>
    for line in loglines:
  File "coding/parsing.py", line 7, in follow
    time.sleep(0.1)
KeyboardInterrupt

下面是我的剧本:

import time
def follow(thefile):
    thefile.seek(0,2)
    while True:
        line = thefile.readline()
        if not line:
            time.sleep(0.1)
            continue
        yield line

if __name__ == '__main__':
    logfile = open("file.log","r")
    logout = open("/parsing.log","w")
    loglines = follow(logfile)
    category={'malware','phishing'}
    severity={'low','medium','critical'}
    for line in loglines:
            col = line.split(",")
        if len(col) >1 and col[33] in category or col[34] in severity:
            logout.write(col[1]+","+col[2]+","+col[3]+","+col[4]+"\n")

        else:
            pass

如何处理?

0 个答案:

没有答案