[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * This file is part of the Symfony package. 5 * 6 * (c) Fabien Potencier <fabien@symfony.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12 namespace Symfony\Component\Console\Logger; 13 14 use Psr\Log\AbstractLogger; 15 use Psr\Log\InvalidArgumentException; 16 use Psr\Log\LogLevel; 17 use Symfony\Component\Console\Output\ConsoleOutputInterface; 18 use Symfony\Component\Console\Output\OutputInterface; 19 20 /** 21 * PSR-3 compliant console logger. 22 * 23 * @author Kévin Dunglas <dunglas@gmail.com> 24 * 25 * @see http://www.php-fig.org/psr/psr-3/ 26 */ 27 class ConsoleLogger extends AbstractLogger 28 { 29 const INFO = 'info'; 30 const ERROR = 'error'; 31 32 private $output; 33 private $verbosityLevelMap = array( 34 LogLevel::EMERGENCY => OutputInterface::VERBOSITY_NORMAL, 35 LogLevel::ALERT => OutputInterface::VERBOSITY_NORMAL, 36 LogLevel::CRITICAL => OutputInterface::VERBOSITY_NORMAL, 37 LogLevel::ERROR => OutputInterface::VERBOSITY_NORMAL, 38 LogLevel::WARNING => OutputInterface::VERBOSITY_NORMAL, 39 LogLevel::NOTICE => OutputInterface::VERBOSITY_VERBOSE, 40 LogLevel::INFO => OutputInterface::VERBOSITY_VERY_VERBOSE, 41 LogLevel::DEBUG => OutputInterface::VERBOSITY_DEBUG, 42 ); 43 private $formatLevelMap = array( 44 LogLevel::EMERGENCY => self::ERROR, 45 LogLevel::ALERT => self::ERROR, 46 LogLevel::CRITICAL => self::ERROR, 47 LogLevel::ERROR => self::ERROR, 48 LogLevel::WARNING => self::INFO, 49 LogLevel::NOTICE => self::INFO, 50 LogLevel::INFO => self::INFO, 51 LogLevel::DEBUG => self::INFO, 52 ); 53 54 public function __construct(OutputInterface $output, array $verbosityLevelMap = array(), array $formatLevelMap = array()) 55 { 56 $this->output = $output; 57 $this->verbosityLevelMap = $verbosityLevelMap + $this->verbosityLevelMap; 58 $this->formatLevelMap = $formatLevelMap + $this->formatLevelMap; 59 } 60 61 /** 62 * {@inheritdoc} 63 */ 64 public function log($level, $message, array $context = array()) 65 { 66 if (!isset($this->verbosityLevelMap[$level])) { 67 throw new InvalidArgumentException(sprintf('The log level "%s" does not exist.', $level)); 68 } 69 70 // Write to the error output if necessary and available 71 if (self::ERROR === $this->formatLevelMap[$level] && $this->output instanceof ConsoleOutputInterface) { 72 $output = $this->output->getErrorOutput(); 73 } else { 74 $output = $this->output; 75 } 76 77 if ($output->getVerbosity() >= $this->verbosityLevelMap[$level]) { 78 $output->writeln(sprintf('<%1$s>[%2$s] %3$s</%1$s>', $this->formatLevelMap[$level], $level, $this->interpolate($message, $context))); 79 } 80 } 81 82 /** 83 * Interpolates context values into the message placeholders. 84 * 85 * @author PHP Framework Interoperability Group 86 * 87 * @param string $message 88 * @param array $context 89 * 90 * @return string 91 */ 92 private function interpolate($message, array $context) 93 { 94 // build a replacement array with braces around the context keys 95 $replace = array(); 96 foreach ($context as $key => $val) { 97 if (!\is_array($val) && (!\is_object($val) || method_exists($val, '__toString'))) { 98 $replace[sprintf('{%s}', $key)] = $val; 99 } 100 } 101 102 // interpolate replacement values into the message and return 103 return strtr($message, $replace); 104 } 105 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |