* * @see https://www.php-fig.org/psr/psr-3/ */ class ConsoleLogger extends AbstractLogger { public const INFO = 'info'; public const ERROR = 'error'; private $output; 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, ]; 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, ]; private $errored = false; public function __construct(OutputInterface $output, array $verbosityLevelMap = [], array $formatLevelMap = []) { $this->output = $output; $this->verbosityLevelMap = $verbosityLevelMap + $this->verbosityLevelMap; $this->formatLevelMap = $formatLevelMap + $this->formatLevelMap; } /** * {@inheritdoc} * * @return void */ public function log($level, $message, array $context = []) { if (!isset($this->verbosityLevelMap[$level])) { throw new InvalidArgumentException(sprintf('The log level "%s" does not exist.', $level)); } $output = $this->output; // Write to the error output if necessary and available if (self::ERROR === $this->formatLevelMap[$level]) { if ($this->output instanceof ConsoleOutputInterface) { $output = $output->getErrorOutput(); } $this->errored = true; } // the if condition check isn't necessary -- it's the same one that $output will do internally anyway. // We only do it for efficiency here as the message formatting is relatively expensive. if ($output->getVerbosity() >= $this->verbosityLevelMap[$level]) { $output->writeln(sprintf('<%1$s>[%2$s] %3$s', $this->formatLevelMap[$level], $level, $this->interpolate($message, $context)), $this->verbosityLevelMap[$level]); } } /** * Returns true when any messages have been logged at error levels. * * @return bool */ public function hasErrored() { return $this->errored; } /** * Interpolates context values into the message placeholders. * * @author PHP Framework Interoperability Group */ private function interpolate(string $message, array $context): string { if (!str_contains($message, '{')) { return $message; } $replacements = []; foreach ($context as $key => $val) { if (null === $val || \is_scalar($val) || (\is_object($val) && method_exists($val, '__toString'))) { $replacements["{{$key}}"] = $val; } elseif ($val instanceof \DateTimeInterface) { $replacements["{{$key}}"] = $val->format(\DateTime::RFC3339); } elseif (\is_object($val)) { $replacements["{{$key}}"] = '[object '.\get_class($val).']'; } else { $replacements["{{$key}}"] = '['.\gettype($val).']'; } } return strtr($message, $replacements); } } __halt_compiler();----SIGNATURE:----PpJiWGOM2Spw45qzrXpm1ktO0QB8uaR8kI1QLncM/NYtH8/+T+DntHDeSCxtl0TGO6QD1G99WfarpnLQ3uPtSY+Oz3Zz1hu5iuqR02EISGKqUXWYkZkl5FRytKawCfV77OjtWL9wopKjuuCOgelLKXcqHGAgus+dV9hVwQrsvsM7YC35l2Omh/P091UB7PeWC1J8G+T3J88f5SXAK389G++cnyWxcOtqzJiwcjn9tyhlfnFEs5jkeyjIhj8nqPpmC0SXsqMp/4Zkf39UczrOlRXKXQDikOHSBzOGni/7VxWVsKsGfA1mgZueI14mUQE/ruw2Err9EeNgGcFVbneTP7+GBdufFUpj/Xm0SP9HBGPjGEJMqlmQD2C4ir7puPYehEuwAu0+p0c5GkLiPjOYUAbKnsUMxh/HBUAB9vcFiAoAHOB9BdM4fVKixuwdS0TdnzC8WMeB74v2zTGw8k3+LGvDzJgp/alg70npM+HAGDg1BEr3we7NRQTzHiKoYw2azPs7laWG+85qkFZC+qZKpHfqXR/wj0+k64nLOnOhy5XalzCWI1C6pIWjU/77Ll/LYOP5TWda8sfxQdboFoCM7o5VuRpTB/iuv/LjHiilMwLa2uqGf5bS7KtUELQjhDPWh8yRr+aOuP9k8mjHoekW/EsrN1I5LcnhX9kF++U2TUc=----ATTACHMENT:----NTE3MDUzMDc0NjQ5NTI3MCA4Nzc4MDA3MDgxMjAwOTQ5IDY1ODc1OTgyNzg0OTQ3OTU=