问题
We have a PHP application running on Apache and want to log all API requests (GET + parameters).
I have seen this post Best way to log POST data in Apache? where it says "the GET requests will be easy, because they will be in the apache log".
However, when I look in our logs, they are not there. What server log settings do I need to have to record GET requests + querystring? No mention of how to do this in https://httpd.apache.org/docs/2.4/logs.html
回答1:
The GET request are logged in the access log file. Read the documentation you provided, especially the Access Log
part is important.
Your Apache host should be configured with something like:
LogLevel info
ErrorLog "/private/var/log/apache2/{hostname}-error.log"
CustomLog "/private/var/log/apache2/{hostname}-access.log" combined
GET requests can then be found in /private/var/log/apache2/{hostname}-access.log
An easy and quick way to do this for debugging purposes is to write a function that logs the POST data.
function logPost() {
if (isset($_POST && !empty($_POST) {
foreach($_POST as $key => $value) {
error_log('=== _POST REQUEST ===');
error_log('_POST: '.$key.' => '.$value);
}
// OR serialise the data but this is less readable
error_log('=== _POST REQUEST ===');
error_log(serialise($_POST));
}
}
POST requests can then be found in /private/var/log/apache2/{hostname}-error.log
来源:https://stackoverflow.com/questions/54008051/log-get-requests-and-querystring-in-php-apache