From 435515e89ab010156e0e2aacac3338ea622b5dd8 Mon Sep 17 00:00:00 2001 From: tlanyan Date: Wed, 13 Jan 2021 17:29:23 +0800 Subject: [PATCH] feat: add time in log --- index.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/index.php b/index.php index 86c8a78..f6b6ad0 100644 --- a/index.php +++ b/index.php @@ -29,16 +29,19 @@ $loop->run(); function handler(Psr\Http\Message\ServerRequestInterface $req) { + $time = date('Y-m-d H:i:s'); $ip = $req->getHeader('REMOTE_ADDR'); if (!$ip) { + // app deal http requests $ip = $req->getServerParams()['REMOTE_ADDR']; } else { + // app is behind nginx $ip = $ip[0]; } $url = $req->getUri()->getPath(); // strip start / $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') { return serveStaticFiles($url); @@ -185,4 +188,4 @@ function normalizeSize(int $size) { } return round($size, 2) . 'GB'; -} \ No newline at end of file +}