feat: add time in log
This commit is contained in:
parent
33ccd5898a
commit
435515e89a
@ -29,16 +29,19 @@ $loop->run();
|
|||||||
|
|
||||||
|
|
||||||
function handler(Psr\Http\Message\ServerRequestInterface $req) {
|
function handler(Psr\Http\Message\ServerRequestInterface $req) {
|
||||||
|
$time = date('Y-m-d H:i:s');
|
||||||
$ip = $req->getHeader('REMOTE_ADDR');
|
$ip = $req->getHeader('REMOTE_ADDR');
|
||||||
if (!$ip) {
|
if (!$ip) {
|
||||||
|
// app deal http requests
|
||||||
$ip = $req->getServerParams()['REMOTE_ADDR'];
|
$ip = $req->getServerParams()['REMOTE_ADDR'];
|
||||||
} else {
|
} else {
|
||||||
|
// app is behind nginx
|
||||||
$ip = $ip[0];
|
$ip = $ip[0];
|
||||||
}
|
}
|
||||||
$url = $req->getUri()->getPath();
|
$url = $req->getUri()->getPath();
|
||||||
// strip start /
|
// strip start /
|
||||||
$url = substr($url, 1);
|
$url = substr($url, 1);
|
||||||
echo "IP:", $ip, ", request url: ", $url, PHP_EOL;
|
echo "$time IP: $ip, request url: , $url", PHP_EOL;
|
||||||
|
|
||||||
if (substr($url, 0, 4) !== 'http') {
|
if (substr($url, 0, 4) !== 'http') {
|
||||||
return serveStaticFiles($url);
|
return serveStaticFiles($url);
|
||||||
@ -185,4 +188,4 @@ function normalizeSize(int $size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return round($size, 2) . 'GB';
|
return round($size, 2) . 'GB';
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user