}
/**
- * @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);
}
/**
->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',
--- /dev/null
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC. All rights reserved. |
+ | |
+ | This work is published under the GNU AGPLv3 license with some |
+ | permitted exceptions and without any warranty. For full license |
+ | and copyright information, see https://civicrm.org/licensing |
+ +--------------------------------------------------------------------+
+ */
+
+namespace Civi\Core;
+
+/**
+ * The LogManager will provide instances of "LoggerInterface".
+ *
+ * @package Civi\Core
+ */
+class LogManager {
+
+ const DEFAULT_LOGGER = 'psr_log';
+
+ private $channels = [];
+
+ /**
+ * Find or create a logger.
+ *
+ * This implementation will look for a service "log.{NAME}". If none is defined,
+ * then it will fallback to the "psr_log" service.
+ *
+ * @param string $channel
+ * Symbolic name of the intended log.
+ * This should correlate to a service "log.{NAME}".
+ *
+ * @return \Psr\Log\LoggerInterface
+ */
+ public function getLog($channel = 'default') {
+ if (!isset($this->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];
+ }
+
+}