PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.12.1
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.12.1
5.12.1 5.12.0 5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / vendor / prefixed / symfony / console / Logger / ConsoleLogger.php
matomo / app / vendor / prefixed / symfony / console / Logger Last commit date
ConsoleLogger.php 1 year ago
ConsoleLogger.php
97 lines
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11 namespace Matomo\Dependencies\Symfony\Component\Console\Logger;
12
13 use Matomo\Dependencies\Psr\Log\AbstractLogger;
14 use Matomo\Dependencies\Psr\Log\InvalidArgumentException;
15 use Matomo\Dependencies\Psr\Log\LogLevel;
16 use Matomo\Dependencies\Symfony\Component\Console\Output\ConsoleOutputInterface;
17 use Matomo\Dependencies\Symfony\Component\Console\Output\OutputInterface;
18 /**
19 * PSR-3 compliant console logger.
20 *
21 * @author Kévin Dunglas <dunglas@gmail.com>
22 *
23 * @see https://www.php-fig.org/psr/psr-3/
24 */
25 class ConsoleLogger extends AbstractLogger
26 {
27 public const INFO = 'info';
28 public const ERROR = 'error';
29 private $output;
30 private $verbosityLevelMap = [LogLevel::EMERGENCY => OutputInterface::VERBOSITY_NORMAL, LogLevel::ALERT => OutputInterface::VERBOSITY_NORMAL, LogLevel::CRITICAL => OutputInterface::VERBOSITY_NORMAL, LogLevel::ERROR => OutputInterface::VERBOSITY_NORMAL, LogLevel::WARNING => OutputInterface::VERBOSITY_NORMAL, LogLevel::NOTICE => OutputInterface::VERBOSITY_VERBOSE, LogLevel::INFO => OutputInterface::VERBOSITY_VERY_VERBOSE, LogLevel::DEBUG => OutputInterface::VERBOSITY_DEBUG];
31 private $formatLevelMap = [LogLevel::EMERGENCY => self::ERROR, LogLevel::ALERT => self::ERROR, LogLevel::CRITICAL => self::ERROR, LogLevel::ERROR => self::ERROR, LogLevel::WARNING => self::INFO, LogLevel::NOTICE => self::INFO, LogLevel::INFO => self::INFO, LogLevel::DEBUG => self::INFO];
32 private $errored = \false;
33 public function __construct(OutputInterface $output, array $verbosityLevelMap = [], array $formatLevelMap = [])
34 {
35 $this->output = $output;
36 $this->verbosityLevelMap = $verbosityLevelMap + $this->verbosityLevelMap;
37 $this->formatLevelMap = $formatLevelMap + $this->formatLevelMap;
38 }
39 /**
40 * {@inheritdoc}
41 *
42 * @return void
43 */
44 public function log($level, $message, array $context = [])
45 {
46 if (!isset($this->verbosityLevelMap[$level])) {
47 throw new InvalidArgumentException(sprintf('The log level "%s" does not exist.', $level));
48 }
49 $output = $this->output;
50 // Write to the error output if necessary and available
51 if (self::ERROR === $this->formatLevelMap[$level]) {
52 if ($this->output instanceof ConsoleOutputInterface) {
53 $output = $output->getErrorOutput();
54 }
55 $this->errored = \true;
56 }
57 // the if condition check isn't necessary -- it's the same one that $output will do internally anyway.
58 // We only do it for efficiency here as the message formatting is relatively expensive.
59 if ($output->getVerbosity() >= $this->verbosityLevelMap[$level]) {
60 $output->writeln(sprintf('<%1$s>[%2$s] %3$s</%1$s>', $this->formatLevelMap[$level], $level, $this->interpolate($message, $context)), $this->verbosityLevelMap[$level]);
61 }
62 }
63 /**
64 * Returns true when any messages have been logged at error levels.
65 *
66 * @return bool
67 */
68 public function hasErrored()
69 {
70 return $this->errored;
71 }
72 /**
73 * Interpolates context values into the message placeholders.
74 *
75 * @author PHP Framework Interoperability Group
76 */
77 private function interpolate(string $message, array $context) : string
78 {
79 if (!str_contains($message, '{')) {
80 return $message;
81 }
82 $replacements = [];
83 foreach ($context as $key => $val) {
84 if (null === $val || \is_scalar($val) || \is_object($val) && method_exists($val, '__toString')) {
85 $replacements["{{$key}}"] = $val;
86 } elseif ($val instanceof \DateTimeInterface) {
87 $replacements["{{$key}}"] = $val->format(\DateTime::RFC3339);
88 } elseif (\is_object($val)) {
89 $replacements["{{$key}}"] = '[object ' . \get_class($val) . ']';
90 } else {
91 $replacements["{{$key}}"] = '[' . \gettype($val) . ']';
92 }
93 }
94 return strtr($message, $replacements);
95 }
96 }
97