kassner / log-parser

PHP Web Server Log Parser Library
Apache License 2.0
334 stars 64 forks source link

FormatException on common apache log format #45

Closed tooltim closed 4 years ago

tooltim commented 4 years ago

Hi,

With the parser set to the common log format, I am getting a formatException with common log format string.

$line='31.32.246.3 - - [18/May/2019:09:26:02 -0400] "GET / HTTP/1.1" 200 3380 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0"';
$parser = new \Kassner\LogParser\LogParser();
$parser->setFormat('"%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"');
$entry = $parser->parse($line);

I get the same exception without changing the log format. From what I see the formats match, any clue why this could happen ?

Thanks

kassner commented 4 years ago

@tooltim your format has an extra " in the beginning, right before %h.

tooltim commented 4 years ago

This is awkward... I triple checked and I just couldn't see it. Thanks a lot !

Well I'll hop on and ask another question : isn't the common log format supposed to be the one that is matched by default ? In a manner that it shouldn't be necessary to explicity set the format ?

Either way, it's great library you got there, it will definitely save me a lot of time, so thank you for this contribution !

kassner commented 4 years ago

@tooltim Common is more of a reference to the Common Log Format that Apache uses. See http://httpd.apache.org/docs/current/mod/mod_log_config.html#examples. If I remember correctly, this is/was the default log format for Apache2 for a long time, but I personally always use the NCSA combined format.

tooltim commented 4 years ago

I see, so it is normal behavior indeed. Thank you !