diff --git a/src/Core.php b/src/Core.php index 4f996bb..3a4bfd6 100644 --- a/src/Core.php +++ b/src/Core.php @@ -186,6 +186,9 @@ private function registerErrorHandler() $ignoreCategory = Config::getInstance()->getConf('LOG.ignoreCategory'); Logger::getInstance()->ignoreCategory($ignoreCategory); + $displayConsole = Config::getInstance()->getConf('LOG.displayConsole'); + Logger::getInstance()->displayConsole($displayConsole); + //初始化追追踪器 $trigger = Di::getInstance()->get(SysConst::TRIGGER_HANDLER); if (!$trigger instanceof TriggerInterface) { diff --git a/src/Logger.php b/src/Logger.php index cbb2211..84a2e2a 100644 --- a/src/Logger.php +++ b/src/Logger.php @@ -21,6 +21,8 @@ class Logger private $logConsole = true; + private $displayConsole = true; + private $ignoreCategory = []; private $logLevel = LoggerInterface::LOG_LEVEL_INFO; @@ -33,6 +35,11 @@ function __construct(LoggerInterface $logger) $this->callback = new Event(); } + public function onLog(): Event + { + return $this->callback; + } + public function logLevel(?int $level = null) { if ($level !== null) { @@ -42,6 +49,16 @@ public function logLevel(?int $level = null) return $this->logLevel; } + public function displayConsole(?bool $is = null) + { + if($is === null){ + return $this->displayConsole; + }else{ + $this->displayConsole = $is; + return $this; + } + } + public function logConsole(?bool $is = null) { if ($is === null) { @@ -72,6 +89,10 @@ public function log(?string $msg, int $logLevel = LoggerInterface::LOG_LEVEL_DEB return; } + if ($this->logConsole) { + $this->console($msg, $logLevel, $category); + } + $this->logger->log($msg, $logLevel, $category); $calls = $this->callback->all(); foreach ($calls as $call) { @@ -81,47 +102,35 @@ public function log(?string $msg, int $logLevel = LoggerInterface::LOG_LEVEL_DEB public function console(?string $msg, int $logLevel = LoggerInterface::LOG_LEVEL_DEBUG, string $category = 'debug') { - if ($logLevel < $this->logLevel) { - return; - } - - if (in_array($category, $this->ignoreCategory)) { - return; - } - - $this->logger->console($msg, $logLevel, $category); - if ($this->logConsole) { - $this->log($msg, $logLevel, $category); + if($this->displayConsole){ + $this->logger->console($msg, $logLevel, $category); } } public function debug(?string $msg, string $category = 'debug') { - $this->console($msg, LoggerInterface::LOG_LEVEL_DEBUG, $category); + $this->log($msg, LoggerInterface::LOG_LEVEL_DEBUG, $category); } public function info(?string $msg, string $category = 'info') { - $this->console($msg, LoggerInterface::LOG_LEVEL_INFO, $category); + $this->log($msg, LoggerInterface::LOG_LEVEL_INFO, $category); } public function notice(?string $msg, string $category = 'notice') { - $this->console($msg, LoggerInterface::LOG_LEVEL_NOTICE, $category); + $this->log($msg, LoggerInterface::LOG_LEVEL_NOTICE, $category); } public function waring(?string $msg, string $category = 'waring') { - $this->console($msg, LoggerInterface::LOG_LEVEL_WARNING, $category); + $this->log($msg, LoggerInterface::LOG_LEVEL_WARNING, $category); } public function error(?string $msg, string $category = 'error') { - $this->console($msg, LoggerInterface::LOG_LEVEL_ERROR, $category); + $this->log($msg, LoggerInterface::LOG_LEVEL_ERROR, $category); } - public function onLog(): Event - { - return $this->callback; - } + } diff --git a/src/Resource/Config._php b/src/Resource/Config._php index a69fc3f..69fccc2 100644 --- a/src/Resource/Config._php +++ b/src/Resource/Config._php @@ -26,6 +26,7 @@ return [ 'level' => LoggerInterface::LOG_LEVEL_DEBUG, 'handler' => null, 'logConsole' => true, + 'displayConsole'=>true, 'ignoreCategory' => [] ], 'TEMP_DIR' => null