From e451efad4f6b120271686647aecf0727463b1563 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Wed, 19 Apr 2023 00:03:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kiri-engine/Abstracts/Logger.php | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/kiri-engine/Abstracts/Logger.php b/kiri-engine/Abstracts/Logger.php index f1c542f2..1912467d 100644 --- a/kiri-engine/Abstracts/Logger.php +++ b/kiri-engine/Abstracts/Logger.php @@ -10,6 +10,7 @@ use Kiri; use Kiri\Server\Events\OnWorkerStop; use Psr\Log\LoggerInterface; use ReflectionException; +use Symfony\Component\Console\Output\OutputInterface; /** @@ -134,20 +135,20 @@ class Logger implements LoggerInterface { // TODO: Implement log() method. $levels = Config::get('log.level', Logger::LOGGER_LEVELS); - if (in_array($level, $levels)) { - $_string = "[" . now() . ']' . ucfirst($level) . ": " . $message . PHP_EOL; - if (!empty($context)) { - $_string .= $this->_string($context); - } - if (str_contains($_string, 'Event::rshutdown')) { - return; - } - file_put_contents('php://output', $_string); - - $filename = storage('log-' . date('Y-m-d') . '.log', 'log/'); - - file_put_contents($filename, $_string, FILE_APPEND); + if (!in_array($level, $levels)) { + return; } + $_string = "[" . now() . ']' . ucfirst($level) . ": " . $message . PHP_EOL; + if (!empty($context)) $_string .= $this->_string($context); + if (str_contains($_string, 'Event::rshutdown')) { + return; + } + + $console = Kiri::getDi()->get(OutputInterface::class); + $console->writeln($_string); + $filename = storage('log-' . date('Y-m-d') . '.log', 'log/'); + + file_put_contents($filename, $_string, FILE_APPEND); }