Comments (4)
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"');
from log-parser.
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"');
from log-parser.
If you still have this problem, the issues are:
%t
already includes the square brackes ([
and]
);- There is an extra
\
before"%{User-Agent}i"
; - The
%
before{
is missing from"{X-Forwarded-For}i"
; - By a limitation on how the parser was implemented, the library is looking for only one
-
when you're defining headers, soX-Forwarded-For
will not work, butXForwarded-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"
}
from log-parser.
Thanks a lot, will get to it when my php-fpm isn't broken anymore
from log-parser.
Related Issues (20)
- Parsing only specific request. Is it possible? HOT 4
- Support for apache error log? HOT 2
- Add support to PCRE2 (PHP 7.3) HOT 1
- custom nginx access log format
- garbage columns HOT 2
- May be can support Nginx error.log? HOT 2
- Syslog support? HOT 1
- FormatException on common apache log format HOT 4
- Fatal error when Apache field 3 is a quoted empty string HOT 2
- Fatal error when POST is not uppercase HOT 1
- Error when trying to parse hexadecimal? HOT 1
- Throws Exceptions when Encountering Real World Logs HOT 2
- responseBytes missing (-) HOT 1
- FormatException when line contains domain\\user_name HOT 6
- Format Exception with Default Nginx Format HOT 2
- Help with Pattern Matching? HOT 3
- Creation of dynamic property is deprecated on PHP 8.2 HOT 2
- Handle '-' in 'sentBytes' and 'receivedBytes' HOT 1
- How to print log entries between 2 dates? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from log-parser.