我在我的代码中使用这个函数来返回我想从读取日志文件中得到的字符串,我想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