From e69a4feb9943bd3eec5842f19676688612652498 Mon Sep 17 00:00:00 2001 From: Foma Tuturov Date: Tue, 13 Feb 2024 17:21:43 +0300 Subject: [PATCH] upd error format --- HlebBootstrap.php | 4 ++-- Init/ErrorLog.php | 25 +++++++++++++++++++------ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/HlebBootstrap.php b/HlebBootstrap.php index cd72321..4b13538 100644 --- a/HlebBootstrap.php +++ b/HlebBootstrap.php @@ -107,7 +107,7 @@ public function __construct(?string $publicPath = null, array $config = [], ?Log // The current version of the framework. // Текущая версия фреймворка. - \defined('HLEB_CORE_VERSION') or \define('HLEB_CORE_VERSION', '2.0.5'); + \defined('HLEB_CORE_VERSION') or \define('HLEB_CORE_VERSION', '2.0.6'); $this->logger = $logger; @@ -691,7 +691,7 @@ protected function scriptErrorHandling(\Throwable $t): void $this->getLogger()->error($t); if (DynamicParams::isDebug()) { - $message = ' ERROR: ' . $t; + $message = PHP_EOL . '
ERROR: ' . $t . '
' . PHP_EOL; } else { $message = ''; } diff --git a/Init/ErrorLog.php b/Init/ErrorLog.php index 7c638ba..c85668d 100644 --- a/Init/ErrorLog.php +++ b/Init/ErrorLog.php @@ -107,7 +107,7 @@ public static function execute(int $errno, string $errstr, string $errfile = nul case E_CORE_ERROR: self::outputNotice(); $log->critical($errstr, $params); - \async_exit($debug ? (SystemSettings::isCli() ? '' : $errstr) : '', 500); + \async_exit($debug ? (SystemSettings::isCli() ? '' : self::format($errstr)) : '', 500); break; case E_ERROR: case E_USER_ERROR: @@ -116,7 +116,7 @@ public static function execute(int $errno, string $errstr, string $errfile = nul case E_RECOVERABLE_ERROR: self::outputNotice(); $log->error($errstr, $params); - \async_exit($debug ? (SystemSettings::isCli() ? '' : $errstr) : '', 500); + \async_exit($debug ? (SystemSettings::isCli() ? '' : self::format($errstr)) : '', 500); break; case E_USER_WARNING: case E_WARNING: @@ -124,7 +124,7 @@ public static function execute(int $errno, string $errstr, string $errfile = nul case E_COMPILE_WARNING: self::outputNotice(); $log->warning($errstr, $params); - $debug and print PHP_EOL . "Warning: $errstr in $errfile:$errline" . PHP_EOL; + $debug and print self::format( "Warning: $errstr in $errfile:$errline"); break; case E_USER_NOTICE: case E_NOTICE: @@ -132,16 +132,15 @@ public static function execute(int $errno, string $errstr, string $errfile = nul case E_DEPRECATED: case E_USER_DEPRECATED: $log->notice($errstr, $params); - $debug and self::$notices[] = PHP_EOL . "Notice: $errstr in $errfile:$errline" . PHP_EOL; + $debug and self::$notices[] = self::format("Notice: $errstr in $errfile:$errline"); break; default: self::outputNotice(); $log->error($errstr, $params); - \async_exit($debug ? (SystemSettings::isCli() ? '' : $errstr) : '', 500); + \async_exit($debug ? (SystemSettings::isCli() ? '' : self::format($errstr)) : '', 500); break; } self::$config and SystemSettings::setData(self::$config); - } catch (\Throwable $t) { \error_log((string)$t); self::$config = []; @@ -308,4 +307,18 @@ private static function outputNotice(): void self::$notices = []; } } + + /** + * Formatting the error output. + * + * Форматирование выводимой ошибки. + */ + private static function format(string $message): string + { + if (SystemSettings::isCli()) { + return $message . PHP_EOL . PHP_EOL; + } + + return PHP_EOL . "
$message
" . PHP_EOL; + } }