parse_line does not get called
jmcbee opened this issue · comments
Hello,
I'm issuing logster with the following command
logster --dry-run --debug --output=stdout --log-dir=log --state-dir=run myparser.CustomParser log.txt
The content of myparser.py is
from logster.logster_helper import MetricObject, LogsterParser
from logster.logster_helper import LogsterParsingException
import re
import logging
class CustomParser(LogsterParser):
def __init__(self, option_string=None):
self.lines = [MetricObject('ip', '0.0.0.0')]
self.reg = re.compile('(?P<ipaddress>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) - - \[(?P<dateandtime>\d{2}\/[a-z]{3}\/\d{4}:\d{2}:\d{2}:\d{2} (\+|\-)\d{4})\] ((\"(GET|POST) )(?P<url>.+)(http\/1\.1")) (?P<statuscode>\d{3}) (?P<bytessent>\d+) (["](?P<refferer>(\-)|(.+))["]) (["](?P<useragent>.+)["])')
def parse_line(self, line):
self.lines.push(MetricObject('ip', '127.0.0.1'))
try:
regMatch = self.reg.match(line)
if regMatch:
logging.debug(regMatch.groupdict())
else:
raise LogsterParsingException("regmatch failed to match")
except Exception as e:
raise LogsterParsingException("regmatch or contents failed with %s" % e)
def get_state(self, duration):
return self.lines
However for some reason, parse_line does not get called.
$ wc -l log.txt
10 log.txt
$ logster --dry-run --debug --output=stdout --log-dir=log --state-dir=run myparser.CustomParser log.txt
1430448601 ip 0.0.0.0
I hope someone can help.
Thank you.
By design, the first run of logster on a new logfile won't process any existing lines. That may be the cause of your issue.
I recommend asking general implementation questions in the #codeascraft irc channel on FreeNode
Hello,
I tried running the command many times but it still does not get called.