feat: Log Util

This commit is contained in:
2024-10-27 21:54:35 +08:00
parent a60c6ea29e
commit 5285dd6972
12 changed files with 320 additions and 13 deletions

View File

@@ -12,6 +12,7 @@ declare(strict_types=1);
namespace App\Exception\Handler;
use App\Lib\Log;
use Hyperf\Contract\StdoutLoggerInterface;
use Hyperf\ExceptionHandler\ExceptionHandler;
use Hyperf\HttpMessage\Stream\SwooleStream;
@@ -20,14 +21,18 @@ use Throwable;
class AppExceptionHandler extends ExceptionHandler
{
public function __construct(protected StdoutLoggerInterface $logger)
public function __construct(protected StdoutLoggerInterface $logger,protected Log $log)
{
}
public function handle(Throwable $throwable, ResponseInterface $response)
{
$this->logger->error(sprintf('%s[%s] in %s', $throwable->getMessage(), $throwable->getLine(), $throwable->getFile()));
$this->logger->error($throwable->getTraceAsString());
// $this->logger->error(sprintf('%s[%s] in %s', $throwable->getMessage(), $throwable->getLine(), $throwable->getFile()));
// $this->logger->error($throwable->getTraceAsString());
$this->log->error(sprintf('%s[%s] in %s', $throwable->getMessage(), $throwable->getLine(), $throwable->getFile()));
$this->log->error($throwable->getTraceAsString());
return $response->withHeader('Server', 'Hyperf')->withStatus(500)->withBody(new SwooleStream('Internal Server Error.'));
}