Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/console/Logger/ConsoleLogger.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 4c8ae668cc8c |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
27 class ConsoleLogger extends AbstractLogger | 27 class ConsoleLogger extends AbstractLogger |
28 { | 28 { |
29 const INFO = 'info'; | 29 const INFO = 'info'; |
30 const ERROR = 'error'; | 30 const ERROR = 'error'; |
31 | 31 |
32 /** | |
33 * @var OutputInterface | |
34 */ | |
35 private $output; | 32 private $output; |
36 /** | |
37 * @var array | |
38 */ | |
39 private $verbosityLevelMap = array( | 33 private $verbosityLevelMap = array( |
40 LogLevel::EMERGENCY => OutputInterface::VERBOSITY_NORMAL, | 34 LogLevel::EMERGENCY => OutputInterface::VERBOSITY_NORMAL, |
41 LogLevel::ALERT => OutputInterface::VERBOSITY_NORMAL, | 35 LogLevel::ALERT => OutputInterface::VERBOSITY_NORMAL, |
42 LogLevel::CRITICAL => OutputInterface::VERBOSITY_NORMAL, | 36 LogLevel::CRITICAL => OutputInterface::VERBOSITY_NORMAL, |
43 LogLevel::ERROR => OutputInterface::VERBOSITY_NORMAL, | 37 LogLevel::ERROR => OutputInterface::VERBOSITY_NORMAL, |
44 LogLevel::WARNING => OutputInterface::VERBOSITY_NORMAL, | 38 LogLevel::WARNING => OutputInterface::VERBOSITY_NORMAL, |
45 LogLevel::NOTICE => OutputInterface::VERBOSITY_VERBOSE, | 39 LogLevel::NOTICE => OutputInterface::VERBOSITY_VERBOSE, |
46 LogLevel::INFO => OutputInterface::VERBOSITY_VERY_VERBOSE, | 40 LogLevel::INFO => OutputInterface::VERBOSITY_VERY_VERBOSE, |
47 LogLevel::DEBUG => OutputInterface::VERBOSITY_DEBUG, | 41 LogLevel::DEBUG => OutputInterface::VERBOSITY_DEBUG, |
48 ); | 42 ); |
49 /** | |
50 * @var array | |
51 */ | |
52 private $formatLevelMap = array( | 43 private $formatLevelMap = array( |
53 LogLevel::EMERGENCY => self::ERROR, | 44 LogLevel::EMERGENCY => self::ERROR, |
54 LogLevel::ALERT => self::ERROR, | 45 LogLevel::ALERT => self::ERROR, |
55 LogLevel::CRITICAL => self::ERROR, | 46 LogLevel::CRITICAL => self::ERROR, |
56 LogLevel::ERROR => self::ERROR, | 47 LogLevel::ERROR => self::ERROR, |
59 LogLevel::INFO => self::INFO, | 50 LogLevel::INFO => self::INFO, |
60 LogLevel::DEBUG => self::INFO, | 51 LogLevel::DEBUG => self::INFO, |
61 ); | 52 ); |
62 private $errored = false; | 53 private $errored = false; |
63 | 54 |
64 /** | |
65 * @param OutputInterface $output | |
66 * @param array $verbosityLevelMap | |
67 * @param array $formatLevelMap | |
68 */ | |
69 public function __construct(OutputInterface $output, array $verbosityLevelMap = array(), array $formatLevelMap = array()) | 55 public function __construct(OutputInterface $output, array $verbosityLevelMap = array(), array $formatLevelMap = array()) |
70 { | 56 { |
71 $this->output = $output; | 57 $this->output = $output; |
72 $this->verbosityLevelMap = $verbosityLevelMap + $this->verbosityLevelMap; | 58 $this->verbosityLevelMap = $verbosityLevelMap + $this->verbosityLevelMap; |
73 $this->formatLevelMap = $formatLevelMap + $this->formatLevelMap; | 59 $this->formatLevelMap = $formatLevelMap + $this->formatLevelMap; |
83 } | 69 } |
84 | 70 |
85 $output = $this->output; | 71 $output = $this->output; |
86 | 72 |
87 // Write to the error output if necessary and available | 73 // Write to the error output if necessary and available |
88 if ($this->formatLevelMap[$level] === self::ERROR) { | 74 if (self::ERROR === $this->formatLevelMap[$level]) { |
89 if ($this->output instanceof ConsoleOutputInterface) { | 75 if ($this->output instanceof ConsoleOutputInterface) { |
90 $output = $output->getErrorOutput(); | 76 $output = $output->getErrorOutput(); |
91 } | 77 } |
92 $this->errored = true; | 78 $this->errored = true; |
93 } | 79 } |
99 } | 85 } |
100 } | 86 } |
101 | 87 |
102 /** | 88 /** |
103 * Returns true when any messages have been logged at error levels. | 89 * Returns true when any messages have been logged at error levels. |
90 * | |
91 * @return bool | |
104 */ | 92 */ |
105 public function hasErrored() | 93 public function hasErrored() |
106 { | 94 { |
107 return $this->errored; | 95 return $this->errored; |
108 } | 96 } |
117 * | 105 * |
118 * @return string | 106 * @return string |
119 */ | 107 */ |
120 private function interpolate($message, array $context) | 108 private function interpolate($message, array $context) |
121 { | 109 { |
122 // build a replacement array with braces around the context keys | 110 if (false === strpos($message, '{')) { |
123 $replace = array(); | 111 return $message; |
112 } | |
113 | |
114 $replacements = array(); | |
124 foreach ($context as $key => $val) { | 115 foreach ($context as $key => $val) { |
125 if (!is_array($val) && (!is_object($val) || method_exists($val, '__toString'))) { | 116 if (null === $val || is_scalar($val) || (\is_object($val) && method_exists($val, '__toString'))) { |
126 $replace[sprintf('{%s}', $key)] = $val; | 117 $replacements["{{$key}}"] = $val; |
118 } elseif ($val instanceof \DateTimeInterface) { | |
119 $replacements["{{$key}}"] = $val->format(\DateTime::RFC3339); | |
120 } elseif (\is_object($val)) { | |
121 $replacements["{{$key}}"] = '[object '.\get_class($val).']'; | |
122 } else { | |
123 $replacements["{{$key}}"] = '['.\gettype($val).']'; | |
127 } | 124 } |
128 } | 125 } |
129 | 126 |
130 // interpolate replacement values into the message and return | 127 return strtr($message, $replacements); |
131 return strtr($message, $replace); | |
132 } | 128 } |
133 } | 129 } |