From 250b5b09281cdef72e72f7b2ef01cda32fdc2c35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 13 Jul 2021 17:06:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- System/Error/ErrorHandler.php | 4 ++-- System/Error/Logger.php | 35 ++++++++--------------------------- 2 files changed, 10 insertions(+), 29 deletions(-) diff --git a/System/Error/ErrorHandler.php b/System/Error/ErrorHandler.php index cb45784f..8c4814f4 100644 --- a/System/Error/ErrorHandler.php +++ b/System/Error/ErrorHandler.php @@ -143,11 +143,11 @@ class ErrorHandler extends Component implements ErrorInterface /** * @param $message - * @param $category + * @param string $category * * @throws Exception */ - public function writer($message, $category = 'app') + public function writer($message, string $category = 'app') { Snowflake::app()->debug($message, $category); } diff --git a/System/Error/Logger.php b/System/Error/Logger.php index 109eb7a1..f04bc5d2 100644 --- a/System/Error/Logger.php +++ b/System/Error/Logger.php @@ -48,7 +48,7 @@ class Logger extends Component */ public function debug(mixed $message, string $method = 'app', $file = null) { - $this->writer($message, $method); + $this->output($message); } @@ -59,7 +59,7 @@ class Logger extends Component */ public function trance(mixed $message, string $method = 'app') { - $this->writer($message, $method); + $this->output($message); } @@ -82,35 +82,25 @@ class Logger extends Component */ public function success(mixed $message, string $method = 'app', $file = null) { - $this->writer($message, $method); + $this->output($message); } /** * @param $message * @param string $method - * @return string + * @return void * @throws Exception */ - private function writer($message, string $method = 'app'): string + private function writer($message, string $method = 'app'): void { $this->print_r($message, $method); - if ($message instanceof Throwable) { - $message = $message->getMessage(); - } else { - if (is_array($message) || is_object($message)) { - $message = $this->arrayFormat($message); - } - } - if (is_array($message)) { - $message = $this->arrayFormat($message); - } + $message = $this->arrayFormat($message); if (!empty($message)) { if (!is_array($this->logs)) { $this->logs = []; } $this->logs[] = [$method, $message]; } - return $message; } @@ -150,7 +140,7 @@ class Logger extends Component public function getLastError(string $application = 'app'): mixed { $filetype = []; - foreach ($this->logs as $key => $val) { + foreach ($this->logs as $val) { if ($val[0] != $application) { continue; } @@ -286,16 +276,7 @@ class Logger extends Component } else if (is_object($data)) { $data = get_object_vars($data); } - - $filetype = []; - foreach ($data as $key => $val) { - if (is_array($val)) { - $filetype[] = $this->arrayFormat($val); - } else { - $filetype[] = (is_string($key) ? $key . ' : ' : '') . $val; - } - } - return implode(PHP_EOL, $filetype); + return Json::encode($data); }