Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
ConsoleLogger.php
001 <?php
002
003 /*
004 * This file is part of the Symfony package.
005 *
006 * (c) Fabien Potencier <fabien@symfony.com>
007 *
008 * For the full copyright and license information, please view the LICENSE
009 * file that was distributed with this source code.
010 */
011
012 namespace Symfony\Component\Console\Logger;
013
014 use Psr\Log\AbstractLogger;
015 use Psr\Log\InvalidArgumentException;
016 use Psr\Log\LogLevel;
017 use Symfony\Component\Console\Output\OutputInterface;
018 use Symfony\Component\Console\Output\ConsoleOutputInterface;
019
020 /**
021 * PSR-3 compliant console logger.
022 *
023 * @author Kévin Dunglas <dunglas@gmail.com>
024 *
025 * @see http://www.php-fig.org/psr/psr-3/
026 */
027 class ConsoleLogger extends AbstractLogger
028 {
029 const INFO = 'info';
030 const ERROR = 'error';
031
032 /**
033 * @var OutputInterface
034 */
035 private $output;
036 /**
037 * @var array
038 */
039 private $verbosityLevelMap = array(
040 LogLevel::EMERGENCY => OutputInterface::VERBOSITY_NORMAL,
041 LogLevel::ALERT => OutputInterface::VERBOSITY_NORMAL,
042 LogLevel::CRITICAL => OutputInterface::VERBOSITY_NORMAL,
043 LogLevel::ERROR => OutputInterface::VERBOSITY_NORMAL,
044 LogLevel::WARNING => OutputInterface::VERBOSITY_NORMAL,
045 LogLevel::NOTICE => OutputInterface::VERBOSITY_VERBOSE,
046 LogLevel::INFO => OutputInterface::VERBOSITY_VERY_VERBOSE,
047 LogLevel::DEBUG => OutputInterface::VERBOSITY_DEBUG,
048 );
049 /**
050 * @var array
051 */
052 private $formatLevelMap = array(
053 LogLevel::EMERGENCY => self::ERROR,
054 LogLevel::ALERT => self::ERROR,
055 LogLevel::CRITICAL => self::ERROR,
056 LogLevel::ERROR => self::ERROR,
057 LogLevel::WARNING => self::INFO,
058 LogLevel::NOTICE => self::INFO,
059 LogLevel::INFO => self::INFO,
060 LogLevel::DEBUG => self::INFO,
061 );
062
063 /**
064 * @param OutputInterface $output
065 * @param array $verbosityLevelMap
066 * @param array $formatLevelMap
067 */
068 public function __construct(OutputInterface $output, array $verbosityLevelMap = array(), array $formatLevelMap = array())
069 {
070 $this->output = $output;
071 $this->verbosityLevelMap = $verbosityLevelMap + $this->verbosityLevelMap;
072 $this->formatLevelMap = $formatLevelMap + $this->formatLevelMap;
073 }
074
075 /**
076 * {@inheritdoc}
077 */
078 public function log($level, $message, array $context = array())
079 {
080 if (!isset($this->verbosityLevelMap[$level])) {
081 throw new InvalidArgumentException(sprintf('The log level "%s" does not exist.', $level));
082 }
083
084 // Write to the error output if necessary and available
085 if ($this->formatLevelMap[$level] === self::ERROR && $this->output instanceof ConsoleOutputInterface) {
086 $output = $this->output->getErrorOutput();
087 } else {
088 $output = $this->output;
089 }
090
091 if ($output->getVerbosity() >= $this->verbosityLevelMap[$level]) {
092 $output->writeln(sprintf('<%1$s>[%2$s] %3$s</%1$s>', $this->formatLevelMap[$level], $level, $this->interpolate($message, $context)));
093 }
094 }
095
096 /**
097 * Interpolates context values into the message placeholders.
098 *
099 * @author PHP Framework Interoperability Group
100 *
101 * @param string $message
102 * @param array $context
103 *
104 * @return string
105 */
106 private function interpolate($message, array $context)
107 {
108 // build a replacement array with braces around the context keys
109 $replace = array();
110 foreach ($context as $key => $val) {
111 if (!is_array($val) && (!is_object($val) || method_exists($val, '__toString'))) {
112 $replace[sprintf('{%s}', $key)] = $val;
113 }
114 }
115
116 // interpolate replacement values into the message and return
117 return strtr($message, $replace);
118 }
119 }
120