#! /usr/bin/env python
# -*- coding: utf-8 -*-

import argparse
import re

pat = (
    '^(?P<month>\w{3})\s+'
    '(?P<day>\d{1,2})\s+'
    '(?P<time>\d{2}:\d{2}:\d{2})\s+'
    '(?P<user>\S+)\s+'
    '(?P<daemon>[^:]+):\s+'
    '(?P<info>.*)$'
)

LOG_RE = re.compile(pat)


def parse_args():
    """
    Parse command line args
    """
    p = argparse.ArgumentParser(
            description='Parse system logs, for fun or something')
    p.add_argument('-l', '--log', dest='log_file', help='The log file')
    p.add_argument('-f', '--filter', dest='filter', help='filter by daemon')
    return p.parse_args()


def main(args):
    """
    run the parser
    """
    rv = list()
    with open(args.log_file) as f:
        for line in f:
            m = LOG_RE.match(line.strip())
            if m is not None:
                rv.append(m.groupdict())
    if args.filter is not None:
        rv = [i for i in rv if args.filter in i.get('daemon', '')]
    for e in rv:
        print e.get('month'), e.get('day'), e.get('daemon'), e.get('info')


if __name__ == '__main__':
    main(parse_args())

9f5855df3e5b1dc2ab02d923e16097c695ab0eba
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import argparse
import re

pat = (
    '^(?P<month>\w{3})\s+'
    '(?P<day>\d{1,2})\s+'
    '(?P<time>\d{2}:\d{2}:\d{2})\s+'
    '(?P<user>\S+)\s+'
    '(?P<daemon>[^:]+):\s+'
    '(?P<info>.*)$'
)

LOG_RE = re.compile(pat)


def parse_args():
    """
    Parse command line args
    """
    p = argparse.ArgumentParser(
            description='Parse system logs, for fun or something')
    p.add_argument('-l', '--log', dest='log_file', help='The log file')
    p.add_argument('-f', '--filter', dest='filter', help='filter by daemon')
    return p.parse_args()


def main(args):
    """
    run the parser
    """
    rv = list()
    with open(args.log_file) as f:
        for line in f:
            m = LOG_RE.match(line.strip())
            if m is not None:
                rv.append(m.groupdict())
    if args.filter is not None:
        rv = [i for i in rv if args.filter in i.get('daemon', '')]
    for e in rv:
        print e.get('month'), e.get('day'), e.get('daemon'), e.get('info')


if __name__ == '__main__':
    main(parse_args())
