diff --git a/Civi.php b/Civi.php index f916756883ed..a018bb54d9d2 100644 --- a/Civi.php +++ b/Civi.php @@ -82,10 +82,16 @@ public static function lockManager() { } /** - * @return \CRM_Core_Error_Log + * Find or create a logger. + * + * @param string $channel + * Symbolic name (or channel) of the intended log. + * This should correlate to a service "log.{NAME}". + * + * @return \Psr\Log\LoggerInterface */ - public static function log() { - return Civi\Core\Container::singleton()->get('psr_log'); + public static function log($channel = 'default') { + return \Civi\Core\Container::singleton()->get('psr_log_manager')->getLog($channel); } /** diff --git a/Civi/Core/Container.php b/Civi/Core/Container.php index 446720da8a0f..b8e0028720f3 100644 --- a/Civi/Core/Container.php +++ b/Civi/Core/Container.php @@ -147,6 +147,9 @@ public function createContainer() { ->setFactory('CRM_Cxn_BAO_Cxn::createRegistrationClient')->setPublic(TRUE); $container->setDefinition('psr_log', new Definition('CRM_Core_Error_Log', []))->setPublic(TRUE); + $container->setDefinition('psr_log_manager', new Definition('Civi\Core\LogManager', []))->setPublic(TRUE); + // With the default log-manager, you may overload a channel by defining a service, e.g. + // $container->setDefinition('log.ipn', new Definition('CRM_Core_Error_Log', []))->setPublic(TRUE); $basicCaches = [ 'js_strings' => 'js_strings', diff --git a/Civi/Core/LogManager.php b/Civi/Core/LogManager.php new file mode 100644 index 000000000000..2c181a09e0e2 --- /dev/null +++ b/Civi/Core/LogManager.php @@ -0,0 +1,46 @@ +channels[$channel])) { + $c = \Civi::container(); + $svc = "log." . $channel; + $this->channels[$channel] = $c->has($svc) ? $c->get($svc) : $c->get(self::DEFAULT_LOGGER); + } + return $this->channels[$channel]; + } + +}