comparison vendor/symfony/http-kernel/Log/Logger.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 af1871eacc83
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
20 * 20 *
21 * @author Kévin Dunglas <dunglas@gmail.com> 21 * @author Kévin Dunglas <dunglas@gmail.com>
22 */ 22 */
23 class Logger extends AbstractLogger 23 class Logger extends AbstractLogger
24 { 24 {
25 private static $levels = array( 25 private static $levels = [
26 LogLevel::DEBUG => 0, 26 LogLevel::DEBUG => 0,
27 LogLevel::INFO => 1, 27 LogLevel::INFO => 1,
28 LogLevel::NOTICE => 2, 28 LogLevel::NOTICE => 2,
29 LogLevel::WARNING => 3, 29 LogLevel::WARNING => 3,
30 LogLevel::ERROR => 4, 30 LogLevel::ERROR => 4,
31 LogLevel::CRITICAL => 5, 31 LogLevel::CRITICAL => 5,
32 LogLevel::ALERT => 6, 32 LogLevel::ALERT => 6,
33 LogLevel::EMERGENCY => 7, 33 LogLevel::EMERGENCY => 7,
34 ); 34 ];
35 35
36 private $minLevelIndex; 36 private $minLevelIndex;
37 private $formatter; 37 private $formatter;
38 private $handle; 38 private $handle;
39 39
55 if (!isset(self::$levels[$minLevel])) { 55 if (!isset(self::$levels[$minLevel])) {
56 throw new InvalidArgumentException(sprintf('The log level "%s" does not exist.', $minLevel)); 56 throw new InvalidArgumentException(sprintf('The log level "%s" does not exist.', $minLevel));
57 } 57 }
58 58
59 $this->minLevelIndex = self::$levels[$minLevel]; 59 $this->minLevelIndex = self::$levels[$minLevel];
60 $this->formatter = $formatter ?: array($this, 'format'); 60 $this->formatter = $formatter ?: [$this, 'format'];
61 if (false === $this->handle = is_resource($output) ? $output : @fopen($output, 'a')) { 61 if (false === $this->handle = \is_resource($output) ? $output : @fopen($output, 'a')) {
62 throw new InvalidArgumentException(sprintf('Unable to open "%s".', $output)); 62 throw new InvalidArgumentException(sprintf('Unable to open "%s".', $output));
63 } 63 }
64 } 64 }
65 65
66 /** 66 /**
67 * {@inheritdoc} 67 * {@inheritdoc}
68 */ 68 */
69 public function log($level, $message, array $context = array()) 69 public function log($level, $message, array $context = [])
70 { 70 {
71 if (!isset(self::$levels[$level])) { 71 if (!isset(self::$levels[$level])) {
72 throw new InvalidArgumentException(sprintf('The log level "%s" does not exist.', $level)); 72 throw new InvalidArgumentException(sprintf('The log level "%s" does not exist.', $level));
73 } 73 }
74 74
88 * @return string 88 * @return string
89 */ 89 */
90 private function format($level, $message, array $context) 90 private function format($level, $message, array $context)
91 { 91 {
92 if (false !== strpos($message, '{')) { 92 if (false !== strpos($message, '{')) {
93 $replacements = array(); 93 $replacements = [];
94 foreach ($context as $key => $val) { 94 foreach ($context as $key => $val) {
95 if (null === $val || is_scalar($val) || (\is_object($val) && method_exists($val, '__toString'))) { 95 if (null === $val || is_scalar($val) || (\is_object($val) && method_exists($val, '__toString'))) {
96 $replacements["{{$key}}"] = $val; 96 $replacements["{{$key}}"] = $val;
97 } elseif ($val instanceof \DateTimeInterface) { 97 } elseif ($val instanceof \DateTimeInterface) {
98 $replacements["{{$key}}"] = $val->format(\DateTime::RFC3339); 98 $replacements["{{$key}}"] = $val->format(\DateTime::RFC3339);