diff --git a/src/Core/CoreException.php b/src/Core/CoreException.php index cc38f96..4e405ba 100644 --- a/src/Core/CoreException.php +++ b/src/Core/CoreException.php @@ -64,6 +64,25 @@ public function capture_errors(bool $turn_warning_to_errors = false) : void exception: $exception, ); }); + + define('LAST_LINE_DEFENCE', E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR); + + register_shutdown_function(function () { + + $error = error_get_last(); + + + if(!empty($error) && ($error['type'] & LAST_LINE_DEFENCE)) { + self::log_always(); + + $this->use_exception( + "ShutdownError", + $error['message'] . PHP_EOL + . "File: " . $error['file'] . ":" . $error['line'] . PHP_EOL, + raw: ["err_code" => $error['type']] + ); + } + }); } public function get_env(): string diff --git a/src/Core/Exception.php b/src/Core/Exception.php index dd67b9b..5bdd5e3 100644 --- a/src/Core/Exception.php +++ b/src/Core/Exception.php @@ -36,10 +36,10 @@ public static function always_log() : void self::new()->log_always(); } - public static function log(mixed $message, Throwable $exception = null) : void + public static function log(mixed $message, Throwable $exception = null, string $log_title = "") : void { self::always_log(); - self::throw_exception(var_export($message, true), "ManualLog", kill: false, exception: $exception, throw_500: false, echo_error: false); + self::throw_exception(var_export($message, true), "ManualLog:$log_title", kill: false, exception: $exception, throw_500: false, echo_error: false); } /**