diff --git a/src/Enum/LoggerChannel.php b/src/Enum/LoggerChannel.php new file mode 100644 index 0000000..fe3be87 --- /dev/null +++ b/src/Enum/LoggerChannel.php @@ -0,0 +1,15 @@ +pushHandler(new RotatingFileHandler($logsDir . '/database.log', Logger::DEBUG)); + $channels = LoggerChannel::getValues(); + foreach($channels as $channel){ + $this->loggers[$channel] = new Logger($channel); + $logsDir = $databasePath . "/" . Database::LOGS_DIR_NAME; + $this->pushHandler(new RotatingFileHandler($logsDir . "/".$channel."log", Logger::DEBUG)); + } + } } diff --git a/src/Service/Engine.php b/src/Service/Engine.php index 6071912..af0e542 100644 --- a/src/Service/Engine.php +++ b/src/Service/Engine.php @@ -12,6 +12,7 @@ use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Filesystem\Filesystem; +use Morebec\YDB\Enum\LoggerChannel; /** * The engine class serves as a service container. @@ -100,14 +101,20 @@ public function dispatchEvent(string $name, DatabaseEvent $event): void * @param string $message message * @param array $context optional context data */ - public function log(string $level, string $message, array $context = []): void + public function log(string $level, string $message, array $context = [],string $channel = LoggerChannel::__DEFAULT): void { if (!$this->logger) { return; } - + Assertion::keyExists($this->logger->loggers, $channel, "Unsupported channel '$channel'"); $context['database_root'] = (string)$this->database->getPath(); - $this->logger->log($level, $message, $context); + $this->logger->loggers[LoggerChannel::__DEFAULT]->log($level, $message, $context); + if ($channel === LoggerChannel::__DEFAULT) { + return; + } + // Log in channel specific logger + $this->logger->loggers[$channel]->log($level, $message, $context); + } /**