-
-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
more improvements, support Nginx error logs
- Loading branch information
Showing
14 changed files
with
303 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace Opcodes\LogViewer; | ||
|
||
use Carbon\CarbonInterface; | ||
use Illuminate\Support\Carbon; | ||
|
||
class HttpNginxErrorLog extends HttpLog | ||
{ | ||
static string $regex = '/^(?P<datetime>[\d+\/ :]+) \[(?P<errortype>.+)\] .*?: (?P<errormessage>.+?)(?:, client: (?P<client>.+?))?(?:, server: (?P<server>.+?))?(?:, request: "?(?P<request>.+?)"?)?(?:, host: "?(?P<host>.+?)"?)?$/'; | ||
|
||
public ?CarbonInterface $datetime; | ||
public ?string $level; | ||
public ?string $message; | ||
public ?string $client; | ||
public ?string $server; | ||
public ?string $request; | ||
public ?string $host; | ||
|
||
public function __construct( | ||
public string $text, | ||
public ?string $fileIdentifier = null, | ||
public ?int $filePosition = null, | ||
) { | ||
parent::__construct($text, $fileIdentifier, $filePosition); | ||
|
||
$matches = $this->parseText($text); | ||
|
||
$this->datetime = $this->parseDateTime($matches['datetime'])?->tz( | ||
config('log-viewer.timezone', config('app.timezone', 'UTC')) | ||
); | ||
$this->level = $matches['level']; | ||
$this->message = $matches['message']; | ||
$this->client = $matches['client']; | ||
$this->server = $matches['server']; | ||
$this->request = $matches['request']; | ||
$this->host = $matches['host']; | ||
} | ||
|
||
public function parseText(string $text): array | ||
{ | ||
$result = preg_match(self::$regex, $this->text, $matches); | ||
|
||
return [ | ||
'datetime' => $matches['datetime'] ?? null, | ||
'level' => $matches['errortype'] ?? null, | ||
'message' => $matches['errormessage'] ?? null, | ||
'client' => isset($matches['client']) ? ($matches['client'] ?: null) : null, | ||
'server' => $matches['server'] ?? null, | ||
'request' => $matches['request'] ?? null, | ||
'host' => $matches['host'] ?? null, | ||
]; | ||
} | ||
|
||
public function parseDateTime(?string $datetime): ?CarbonInterface | ||
{ | ||
return $datetime ? Carbon::createFromFormat('Y/m/d H:i:s', $datetime) : null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
2023/01/04 11:18:33 [alert] 95160#0: *1473 setsockopt(TCP_NODELAY) failed (22: Invalid argument) while keepalive, client: 127.0.0.1, server: 127.0.0.1:80 | ||
2023/07/01 22:05:03 [warn] 21925#0: the "listen ... http2" directive is deprecated, use the "http2" directive instead in /Users/test/.config/valet/Nginx/blog9.test:9 | ||
2023/07/01 22:05:03 [warn] 21925#0: the "http2_push_preload" directive is obsolete, ignored in /Users/test/.config/valet/Nginx/blog9.test:15 | ||
2023/07/01 22:05:03 [warn] 21925#0: the "listen ... http2" directive is deprecated, use the "http2" directive instead in /Users/test/.config/valet/Nginx/system.test:9 | ||
2023/07/01 22:05:03 [warn] 21925#0: the "http2_push_preload" directive is obsolete, ignored in /Users/test/.config/valet/Nginx/system.test:15 | ||
2023/07/01 22:05:09 [warn] 22583#0: the "listen ... http2" directive is deprecated, use the "http2" directive instead in /Users/test/.config/valet/Nginx/blog9.test:9 | ||
2023/07/01 22:05:09 [warn] 22583#0: the "http2_push_preload" directive is obsolete, ignored in /Users/test/.config/valet/Nginx/blog9.test:15 | ||
2023/07/01 22:05:09 [warn] 22583#0: the "listen ... http2" directive is deprecated, use the "http2" directive instead in /Users/test/.config/valet/Nginx/system.test:9 | ||
2023/07/01 22:05:09 [warn] 22583#0: the "http2_push_preload" directive is obsolete, ignored in /Users/test/.config/valet/Nginx/system.test:15 |
Oops, something went wrong.