* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Console\Logger; use Psr\Log\AbstractLogger; use Psr\Log\InvalidArgumentException; use Psr\Log\LogLevel; use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Output\OutputInterface; /** * PSR-3 compliant console logger. * * @author Kévin Dunglas * * @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:----dlrOUcb0zD2T3uqM1skkOg73sAX6kmP99e07jTTXdWGe3ceqi+hv1FD98ZfozDPFxwP+SOIWqFW8qqxMOtmsLmLNuK0S+j7rYLBvqhXu+ICp04ITEZCSZHBYLB6KcQFJoL9hDMhhTCzvgCJzoUuxIxifoxm+cYF/WcHj4324xDpCZSlK++5Eg40fC+L7HUig6Kb9EtnyDfuyQzuC0yg0LXk2WWmfjNjDyE4K8U1U7h1x3GLF2Yg80cNkEsCwTWaUDdGXfL6h+2ioX+YdvrSnH5SXTGKSW0Vpakp8QTYCktDKC0UTQtyAIAxr89YWtID/Th/gi4JsoUwjLA2Ia5zCF6eSwWOiaBa8b8QdZnPXNaA1LYLShdE1+DLqLasZ0ItGmb3YZ7+EFmZeByUE6DeK89ac4EXVI4JD10r9lNeb/qqmMeAQjcEUVooqd+6b/r2TWp/+xxCj4Wvwhhm26LZ0ikJ+yWsvbU/0VvykfbQVYPFRsj2f/8hCNy3Pk956TqpMEMxBndiU+0E3ezVdY25+lP6wwI2H9ZJ2n46EK7/AwR77rfcr9kt/DO60beS4HhIqHM6EujWtYg1eys0NGDRAzDodc3aj0bOzEfJfE9MEqNR+jXlDrjhtIQXYd4khn3pvz4YI/gr5mFvVGJVG/2f453EmbDNVJ/vV+RyYJUYa380=----ATTACHMENT:----MzEzMTEwMzE0MjgwMDMzNCAxMTgyNjI5MzI2MzQyMDYgMjM5NDU0ODczOTQ1ODQ0OA==