This commit is contained in:
2025-12-31 00:19:31 +08:00
parent 87e7535f27
commit baea90e9e5
6 changed files with 763 additions and 811 deletions
+2 -2
View File
@@ -89,7 +89,7 @@ class ErrorHandler extends Component implements ErrorInterface
return;
}
$this->getLogger()->failure($lastError['message'] . PHP_EOL);
$this->getLogger()->logCategory($lastError['message'] . PHP_EOL);
event(new OnSystemError());
}
@@ -104,7 +104,7 @@ class ErrorHandler extends Component implements ErrorInterface
{
$this->category = 'exception';
$this->getLogger()->failure($exception);
$this->getLogger()->logCategory($exception);
event(new OnSystemError());
}
+22 -19
View File
@@ -9,6 +9,7 @@ use Monolog\Formatter\LineFormatter;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Logger;
use Psr\Log\LoggerInterface;
use Throwable;
/**
@@ -67,31 +68,32 @@ class StdoutLogger extends Component
* @param string $model
* @return bool
*/
public function failure($message, string $model = 'app'): bool
public function logCategory($message, string $model = 'app'): bool
{
if ($message instanceof \Exception) {
$this->errors[$model] = $message->getMessage();
} else {
$this->errors[$model] = $message;
}
return $this->dump($message);
$this->println($message);
return false;
}
/**
* @param $message
* @return bool
*/
protected function dump($message): bool
{
$message = throwable($message);
if (str_contains($message, 'inotify_rm_watch')) {
return false;
}
file_put_contents('php://output', '[' . date('Y-m-d H:i:s') . '] ' . $message, FILE_APPEND);
$this->error($message, []);
return false;
}
/**
* @param Throwable $exception
* @param array $data
* @param mixed|null $result
* @return bool
*/
public function json_log(Throwable $exception, array $data = [], mixed $result = null): mixed
{
json_log($exception, $data);
$this->println($exception->getMessage());
return $result;
}
/**
@@ -118,9 +120,10 @@ class StdoutLogger extends Component
} else if (method_exists($this, $name)) {
$this->{$name}(...$arguments);
}
} catch (\Throwable $exception) {
file_put_contents('php://output', '[' . date('Y-m-d H:i:s') . '] ' . $exception->getMessage(), FILE_APPEND);
}
} catch (Throwable $exception) {
$this->println($exception->getMessage());
$this->json_log($exception);
}
}