Closed Bluscream closed 4 years ago
I tried modifying it in favor of better readability:
Fatal error: Uncaught Kassner\LogParser\FormatException: [10/Jun/2020:18:01:45 +0200] IP:"192.168.2.29" (FWD:"-") USER:"blu" DOMAIN:"192.168.2.38" REQUEST:"GET /admin/access.log.php HTTP/1.1" STATUS:200 BYTES_SENT:31 REFERER:"http://192.168.2.38/admin/" UA:"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0" in /var/www/html/admin/vendor/kassner/log-parser/src/LogParser.php:82 Stack trace: #0 /var/www/html/admin/access.log.php(18): Kassner\LogParser\LogParser->parse('[10/Jun/2020:18...') #1 {main} thrown in /var/www/html/admin/vendor/kassner/log-parser/src/LogParser.php on line 82
// '[$time_local] IP:"$remote_addr" (FWD:"$http_x_forwarded_for") USER:"$remote_user" DOMAIN:"$host" REQUEST:"$request" STATUS:$status BYTES_SENT:$body_bytes_sent REFERER:"$http_referer" UA:"$http_user_agent"';
$parser->setFormat('[%t] IP:"%h" (FWD:"%{X-Forwarded-For}i") USER:"%u" DOMAIN:"%v" REQUEST:"%r" STATUS:%>s BYTES_SENT:%O REFERER:"%{Referer}i" UA:"%{User-Agent}i"');
My attempt at a better format:
Fatal error: Uncaught Kassner\LogParser\FormatException:
[10/Jun/2020:18:01:45 +0200]
IP:"192.168.2.29"
(FWD:"-")
USER:"blu"
DOMAIN:"192.168.2.38"
REQUEST:"GET /admin/access.log.php HTTP/1.1"
STATUS:200
BYTES_SENT:31
REFERER:"http://192.168.2.38/admin/" UA:"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0"
in /var/www/html/admin/vendor/kassner/log-parser/src/LogParser.php:82
Stack trace:
#0 /var/www/html/admin/access.log.php(18): Kassner\LogParser\LogParser->parse('[10/Jun/2020:18...')
#1 {main} thrown in /var/www/html/admin/vendor/kassner/log-parser/src/LogParser.php on line 82
// '[$time_local] IP:"$remote_addr" (FWD:"$http_x_forwarded_for") USER:"$remote_user" DOMAIN:"$host" REQUEST:"$request" STATUS:$status BYTES_SENT:$body_bytes_sent REFERER:"$http_referer" UA:"$http_user_agent"';
$parser->setFormat('[%t] IP:"%h" (FWD:"%{X-Forwarded-For}i") USER:"%u" DOMAIN:"%v" REQUEST:"%r" STATUS:%>s BYTES_SENT:%O REFERER:"%{Referer}i" UA:"%{User-Agent}i"');
If you still have this problem, the issues are:
%t
already includes the square brackes ([
and ]
);\
before "%{User-Agent}i"
;%
before {
is missing from "{X-Forwarded-For}i"
;-
when you're defining headers, so X-Forwarded-For
will not work, but XForwarded-For
will.So your setFormat
should be:
$parser->setFormat('%a - %u %t "%v" "%r" %>s %O "%{Referer}i" "%{User-Agent}i" "%{XForwarded-For}i"');
Which will yield:
object(Kassner\LogParser\SimpleLogEntry)#357 (11) {
["stamp"]=>
int(1591804006)
["remoteIp"]=>
string(14) "172.68.189.227"
["user"]=>
string(1) "-"
["time"]=>
string(26) "10/Jun/2020:17:46:46 +0200"
["serverName"]=>
string(10) "minopia.de"
["request"]=>
string(15) "POST / HTTP/1.1"
["status"]=>
string(3) "405"
["sentBytes"]=>
string(3) "575"
["HeaderReferer"]=>
string(1) "-"
["HeaderUserAgent"]=>
string(152) "Mozlila/5.0 (Linux; Android 7.0; SM-G892A Bulid/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/60.0.3112.107 Moblie Safari/537.36"
["HeaderXForwardedFor"]=>
string(13) "13.91.103.115"
}
Thanks a lot, will get to it when my php-fpm isn't broken anymore
nginx.conf
:php file:
access.log
: