kassner / log-parser

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

Parsing only specific request. Is it possible? #33

Closed wabsa closed 7 years ago

wabsa commented 7 years ago

I have an api that i need to track each access log. Is there a way to parse only the request that are coming from my API request? Thanks

kassner commented 7 years ago

You can either parse all lines and filter out the ones that you don't need or configure your webserver to only log the requests you want to a separate file.

wabsa commented 7 years ago

Thanks, another question what is correct format for HTTP/2.0 got format exception if we use http/2.0 heres my current format:

$parser->setFormat('%h %l %u %t "%r" %>s %O "%{Referer}i" \"%{User-Agent}i" "%D.%T sec"');

Here's the actual logs:

127.0.0.1 - - [16/Aug/2017:17:46:05 +0000] "GET /api/test?api_token=ajsdfhasdj HTTP/2.0" 422 211 "-" "Mozilla/5.0 (X11; Linux x8 6_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36" "-" "0.069 sec"

and here's the log format of my nginx:


log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for" "$request_time sec"';
kassner commented 7 years ago

You can either use a custom format like mentioned in #26 or use the feature/http2 branch, but I am not sure yet when to release that because I haven't been able to create any tests for it.

wabsa commented 7 years ago

Thanks! I will pull your http2 branch for now.