python logparse search specific text

Posted by krisdigitx on Stack Overflow See other posts from Stack Overflow or by krisdigitx
Published on 2010-05-13T12:33:42Z Indexed on 2010/05/13 13:04 UTC
Read the original article Hit count: 266

Filed under:
|
|

hi,

I am using this function in my code to return the strings i want from reading the log file, I want to grep the "exim" process and return the results, but running the code gives no error, but the output is limited to three lines, how can i just get the output only related to exim process..

#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

© Stack Overflow or respective owner

Related posts about python

Related posts about log