comparison vendor/symfony/console/Logger/ConsoleLogger.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 1fec387a4317
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
12 namespace Symfony\Component\Console\Logger; 12 namespace Symfony\Component\Console\Logger;
13 13
14 use Psr\Log\AbstractLogger; 14 use Psr\Log\AbstractLogger;
15 use Psr\Log\InvalidArgumentException; 15 use Psr\Log\InvalidArgumentException;
16 use Psr\Log\LogLevel; 16 use Psr\Log\LogLevel;
17 use Symfony\Component\Console\Output\ConsoleOutputInterface;
17 use Symfony\Component\Console\Output\OutputInterface; 18 use Symfony\Component\Console\Output\OutputInterface;
18 use Symfony\Component\Console\Output\ConsoleOutputInterface;
19 19
20 /** 20 /**
21 * PSR-3 compliant console logger. 21 * PSR-3 compliant console logger.
22 * 22 *
23 * @author Kévin Dunglas <dunglas@gmail.com> 23 * @author Kévin Dunglas <dunglas@gmail.com>
28 { 28 {
29 const INFO = 'info'; 29 const INFO = 'info';
30 const ERROR = 'error'; 30 const ERROR = 'error';
31 31
32 private $output; 32 private $output;
33 private $verbosityLevelMap = array( 33 private $verbosityLevelMap = [
34 LogLevel::EMERGENCY => OutputInterface::VERBOSITY_NORMAL, 34 LogLevel::EMERGENCY => OutputInterface::VERBOSITY_NORMAL,
35 LogLevel::ALERT => OutputInterface::VERBOSITY_NORMAL, 35 LogLevel::ALERT => OutputInterface::VERBOSITY_NORMAL,
36 LogLevel::CRITICAL => OutputInterface::VERBOSITY_NORMAL, 36 LogLevel::CRITICAL => OutputInterface::VERBOSITY_NORMAL,
37 LogLevel::ERROR => OutputInterface::VERBOSITY_NORMAL, 37 LogLevel::ERROR => OutputInterface::VERBOSITY_NORMAL,
38 LogLevel::WARNING => OutputInterface::VERBOSITY_NORMAL, 38 LogLevel::WARNING => OutputInterface::VERBOSITY_NORMAL,
39 LogLevel::NOTICE => OutputInterface::VERBOSITY_VERBOSE, 39 LogLevel::NOTICE => OutputInterface::VERBOSITY_VERBOSE,
40 LogLevel::INFO => OutputInterface::VERBOSITY_VERY_VERBOSE, 40 LogLevel::INFO => OutputInterface::VERBOSITY_VERY_VERBOSE,
41 LogLevel::DEBUG => OutputInterface::VERBOSITY_DEBUG, 41 LogLevel::DEBUG => OutputInterface::VERBOSITY_DEBUG,
42 ); 42 ];
43 private $formatLevelMap = array( 43 private $formatLevelMap = [
44 LogLevel::EMERGENCY => self::ERROR, 44 LogLevel::EMERGENCY => self::ERROR,
45 LogLevel::ALERT => self::ERROR, 45 LogLevel::ALERT => self::ERROR,
46 LogLevel::CRITICAL => self::ERROR, 46 LogLevel::CRITICAL => self::ERROR,
47 LogLevel::ERROR => self::ERROR, 47 LogLevel::ERROR => self::ERROR,
48 LogLevel::WARNING => self::INFO, 48 LogLevel::WARNING => self::INFO,
49 LogLevel::NOTICE => self::INFO, 49 LogLevel::NOTICE => self::INFO,
50 LogLevel::INFO => self::INFO, 50 LogLevel::INFO => self::INFO,
51 LogLevel::DEBUG => self::INFO, 51 LogLevel::DEBUG => self::INFO,
52 ); 52 ];
53 private $errored = false; 53 private $errored = false;
54 54
55 public function __construct(OutputInterface $output, array $verbosityLevelMap = array(), array $formatLevelMap = array()) 55 public function __construct(OutputInterface $output, array $verbosityLevelMap = [], array $formatLevelMap = [])
56 { 56 {
57 $this->output = $output; 57 $this->output = $output;
58 $this->verbosityLevelMap = $verbosityLevelMap + $this->verbosityLevelMap; 58 $this->verbosityLevelMap = $verbosityLevelMap + $this->verbosityLevelMap;
59 $this->formatLevelMap = $formatLevelMap + $this->formatLevelMap; 59 $this->formatLevelMap = $formatLevelMap + $this->formatLevelMap;
60 } 60 }
61 61
62 /** 62 /**
63 * {@inheritdoc} 63 * {@inheritdoc}
64 */ 64 */
65 public function log($level, $message, array $context = array()) 65 public function log($level, $message, array $context = [])
66 { 66 {
67 if (!isset($this->verbosityLevelMap[$level])) { 67 if (!isset($this->verbosityLevelMap[$level])) {
68 throw new InvalidArgumentException(sprintf('The log level "%s" does not exist.', $level)); 68 throw new InvalidArgumentException(sprintf('The log level "%s" does not exist.', $level));
69 } 69 }
70 70
109 { 109 {
110 if (false === strpos($message, '{')) { 110 if (false === strpos($message, '{')) {
111 return $message; 111 return $message;
112 } 112 }
113 113
114 $replacements = array(); 114 $replacements = [];
115 foreach ($context as $key => $val) { 115 foreach ($context as $key => $val) {
116 if (null === $val || is_scalar($val) || (\is_object($val) && method_exists($val, '__toString'))) { 116 if (null === $val || is_scalar($val) || (\is_object($val) && method_exists($val, '__toString'))) {
117 $replacements["{{$key}}"] = $val; 117 $replacements["{{$key}}"] = $val;
118 } elseif ($val instanceof \DateTimeInterface) { 118 } elseif ($val instanceof \DateTimeInterface) {
119 $replacements["{{$key}}"] = $val->format(\DateTime::RFC3339); 119 $replacements["{{$key}}"] = $val->format(\DateTime::RFC3339);