我在我的代碼中使用這個函數來返回我想從讀取日誌文件中得到的字符串,我想grep「exim」過程並返回結果,但運行代碼時沒有提供任何錯誤,但產量只有三行,我如何才能獲得只涉及到進出口過程中的輸出..python logparse搜索特定文本
#output:
{'date': '13', 'process': 'syslogd', 'time': '06:27:33', 'month': 'May'}
{'date': '13', 'process': 'exim[23168]:', 'time': '06:27:33', 'month': 'May'}
{'May': ['syslogd']}
#function:
def generate_log_report(logfile):
report_dict = {}
for line in logfile:
line_dict = dictify_logline(line)
print line_dict
try:
month = line_dict['month']
date = line_dict['date']
time = line_dict['time']
#process = line_dict['process']
if "exim" in line_dict['process']:
process = line_dict['process']
break
else:
process = line_dict['process']
except ValueError:
continue
report_dict.setdefault(month, []).append(process)
return report_dict
我加入 「打印L」 else子句前和工作!但我不明白爲什麼「RETURN L」沒有工作... – krisdigitx 2010-05-14 10:33:46