71 lines
3.8 KiB
YAML
71 lines
3.8 KiB
YAML
name: ConsoleLogger
|
|
class_comment: "# * PSR-3 compliant console logger.\n# *\n# * @author K\xE9vin Dunglas\
|
|
\ <dunglas@gmail.com>\n# *\n# * @see https://www.php-fig.org/psr/psr-3/"
|
|
dependencies:
|
|
- name: AbstractLogger
|
|
type: class
|
|
source: Psr\Log\AbstractLogger
|
|
- name: InvalidArgumentException
|
|
type: class
|
|
source: Psr\Log\InvalidArgumentException
|
|
- name: LogLevel
|
|
type: class
|
|
source: Psr\Log\LogLevel
|
|
- name: ConsoleOutputInterface
|
|
type: class
|
|
source: Symfony\Component\Console\Output\ConsoleOutputInterface
|
|
- name: OutputInterface
|
|
type: class
|
|
source: Symfony\Component\Console\Output\OutputInterface
|
|
properties: []
|
|
methods:
|
|
- name: hasErrored
|
|
visibility: public
|
|
parameters: []
|
|
comment: "# * PSR-3 compliant console logger.\n# *\n# * @author K\xE9vin Dunglas\
|
|
\ <dunglas@gmail.com>\n# *\n# * @see https://www.php-fig.org/psr/psr-3/\n# */\n\
|
|
# class ConsoleLogger extends AbstractLogger\n# {\n# public const INFO = 'info';\n\
|
|
# public const ERROR = 'error';\n# \n# private array $verbosityLevelMap = [\n\
|
|
# LogLevel::EMERGENCY => OutputInterface::VERBOSITY_NORMAL,\n# LogLevel::ALERT\
|
|
\ => OutputInterface::VERBOSITY_NORMAL,\n# LogLevel::CRITICAL => OutputInterface::VERBOSITY_NORMAL,\n\
|
|
# LogLevel::ERROR => OutputInterface::VERBOSITY_NORMAL,\n# LogLevel::WARNING =>\
|
|
\ OutputInterface::VERBOSITY_NORMAL,\n# LogLevel::NOTICE => OutputInterface::VERBOSITY_VERBOSE,\n\
|
|
# LogLevel::INFO => OutputInterface::VERBOSITY_VERY_VERBOSE,\n# LogLevel::DEBUG\
|
|
\ => OutputInterface::VERBOSITY_DEBUG,\n# ];\n# private array $formatLevelMap\
|
|
\ = [\n# LogLevel::EMERGENCY => self::ERROR,\n# LogLevel::ALERT => self::ERROR,\n\
|
|
# LogLevel::CRITICAL => self::ERROR,\n# LogLevel::ERROR => self::ERROR,\n# LogLevel::WARNING\
|
|
\ => self::INFO,\n# LogLevel::NOTICE => self::INFO,\n# LogLevel::INFO => self::INFO,\n\
|
|
# LogLevel::DEBUG => self::INFO,\n# ];\n# private bool $errored = false;\n# \n\
|
|
# public function __construct(\n# private OutputInterface $output,\n# array $verbosityLevelMap\
|
|
\ = [],\n# array $formatLevelMap = [],\n# ) {\n# $this->verbosityLevelMap = $verbosityLevelMap\
|
|
\ + $this->verbosityLevelMap;\n# $this->formatLevelMap = $formatLevelMap + $this->formatLevelMap;\n\
|
|
# }\n# \n# public function log($level, $message, array $context = []): void\n\
|
|
# {\n# if (!isset($this->verbosityLevelMap[$level])) {\n# throw new InvalidArgumentException(\\\
|
|
sprintf('The log level \"%s\" does not exist.', $level));\n# }\n# \n# $output\
|
|
\ = $this->output;\n# \n# // Write to the error output if necessary and available\n\
|
|
# if (self::ERROR === $this->formatLevelMap[$level]) {\n# if ($this->output instanceof\
|
|
\ ConsoleOutputInterface) {\n# $output = $output->getErrorOutput();\n# }\n# $this->errored\
|
|
\ = true;\n# }\n# \n# // the if condition check isn't necessary -- it's the same\
|
|
\ one that $output will do internally anyway.\n# // We only do it for efficiency\
|
|
\ here as the message formatting is relatively expensive.\n# if ($output->getVerbosity()\
|
|
\ >= $this->verbosityLevelMap[$level]) {\n# $output->writeln(\\sprintf('<%1$s>[%2$s]\
|
|
\ %3$s</%1$s>', $this->formatLevelMap[$level], $level, $this->interpolate($message,\
|
|
\ $context)), $this->verbosityLevelMap[$level]);\n# }\n# }\n# \n# /**\n# * Returns\
|
|
\ true when any messages have been logged at error levels."
|
|
- name: interpolate
|
|
visibility: private
|
|
parameters:
|
|
- name: message
|
|
- name: context
|
|
comment: '# * Interpolates context values into the message placeholders.
|
|
|
|
# *
|
|
|
|
# * @author PHP Framework Interoperability Group'
|
|
traits:
|
|
- Psr\Log\AbstractLogger
|
|
- Psr\Log\InvalidArgumentException
|
|
- Psr\Log\LogLevel
|
|
- Symfony\Component\Console\Output\ConsoleOutputInterface
|
|
- Symfony\Component\Console\Output\OutputInterface
|
|
interfaces: []
|