diff --git a/function.php b/function.php index d72d190e..88ea6513 100644 --- a/function.php +++ b/function.php @@ -897,11 +897,14 @@ if (!function_exists('throwable')) { /** - * @param Throwable|Error $throwable + * @param Throwable|Error|string $throwable * @return string */ - function throwable(\Throwable|\Error $throwable): string + function throwable(\Throwable|\Error|string $throwable): string { + if (is_string($throwable)) { + return $throwable; + } $message = "\033[31m" . $throwable::class . ' ' . $throwable->getMessage() . "\033[0m" . PHP_EOL; $message .= $throwable->getFile() . " at line " . $throwable->getLine() . PHP_EOL; diff --git a/kiri-engine/Abstracts/Logger.php b/kiri-engine/Abstracts/Logger.php index c29594fd..91e435ad 100644 --- a/kiri-engine/Abstracts/Logger.php +++ b/kiri-engine/Abstracts/Logger.php @@ -242,9 +242,15 @@ class Logger implements LoggerInterface if ($context instanceof \Throwable) { return 'file -> ' . $context->getFile() . PHP_EOL . 'line -> ' . $context->getLine() . PHP_EOL; } - if (is_array($context) && isset($context[0]) && $context[0] instanceof \Throwable) { - return 'file -> ' . $context[0]->getFile() . PHP_EOL . 'line -> ' . $context[0]->getLine() . PHP_EOL; + + if (!is_array($context)) { + return "unknown"; } - return implode(PHP_EOL, $context); + + $data = []; + foreach ($context as $value) { + $data[] = $this->_string($value); + } + return implode(PHP_EOL, $data); } }