Commit | Line | Data |
---|---|---|
c213eb51 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | Copyright CiviCRM LLC. All rights reserved. | | |
5 | | | | |
6 | | This work is published under the GNU AGPLv3 license with some | | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
9 | +--------------------------------------------------------------------+ | |
10 | */ | |
11 | ||
12 | namespace Civi\Core; | |
13 | ||
14 | /** | |
15 | * The LogManager will provide instances of "LoggerInterface". | |
16 | * | |
17 | * @package Civi\Core | |
18 | */ | |
19 | class LogManager { | |
20 | ||
21 | const DEFAULT_LOGGER = 'psr_log'; | |
22 | ||
23 | private $channels = []; | |
24 | ||
25 | /** | |
26 | * Find or create a logger. | |
27 | * | |
28 | * This implementation will look for a service "log.{NAME}". If none is defined, | |
29 | * then it will fallback to the "psr_log" service. | |
30 | * | |
31 | * @param string $channel | |
32 | * Symbolic name of the intended log. | |
33 | * This should correlate to a service "log.{NAME}". | |
34 | * | |
35 | * @return \Psr\Log\LoggerInterface | |
36 | */ | |
37 | public function getLog($channel = 'default') { | |
38 | if (!isset($this->channels[$channel])) { | |
39 | $c = \Civi::container(); | |
40 | $svc = "log." . $channel; | |
41 | $this->channels[$channel] = $c->has($svc) ? $c->get($svc) : $c->get(self::DEFAULT_LOGGER); | |
42 | } | |
43 | return $this->channels[$channel]; | |
44 | } | |
45 | ||
46 | } |