summaryrefslogtreecommitdiff
path: root/vendor/symfony/console/Logger/ConsoleLogger.php
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2017-12-15 11:24:35 -0800
committerFrédéric Guillot <fred@kanboard.net>2017-12-15 11:55:42 -0800
commita93b8e10f5954be0853eec693c13e84c4bd9e6f2 (patch)
treeeda5de9494b819235616e8623bb3393e9cc373af /vendor/symfony/console/Logger/ConsoleLogger.php
parent2c72a283f2d51034f85f4e2ca8b194d304a3c433 (diff)
Kanboard requires at least PHP 5.6 now
Diffstat (limited to 'vendor/symfony/console/Logger/ConsoleLogger.php')
-rw-r--r--vendor/symfony/console/Logger/ConsoleLogger.php62
1 files changed, 36 insertions, 26 deletions
diff --git a/vendor/symfony/console/Logger/ConsoleLogger.php b/vendor/symfony/console/Logger/ConsoleLogger.php
index 1f7417ea..05dd3b96 100644
--- a/vendor/symfony/console/Logger/ConsoleLogger.php
+++ b/vendor/symfony/console/Logger/ConsoleLogger.php
@@ -22,20 +22,14 @@ use Symfony\Component\Console\Output\ConsoleOutputInterface;
*
* @author Kévin Dunglas <dunglas@gmail.com>
*
- * @link http://www.php-fig.org/psr/psr-3/
+ * @see http://www.php-fig.org/psr/psr-3/
*/
class ConsoleLogger extends AbstractLogger
{
const INFO = 'info';
const ERROR = 'error';
- /**
- * @var OutputInterface
- */
private $output;
- /**
- * @var array
- */
private $verbosityLevelMap = array(
LogLevel::EMERGENCY => OutputInterface::VERBOSITY_NORMAL,
LogLevel::ALERT => OutputInterface::VERBOSITY_NORMAL,
@@ -46,9 +40,6 @@ class ConsoleLogger extends AbstractLogger
LogLevel::INFO => OutputInterface::VERBOSITY_VERY_VERBOSE,
LogLevel::DEBUG => OutputInterface::VERBOSITY_DEBUG,
);
- /**
- * @var array
- */
private $formatLevelMap = array(
LogLevel::EMERGENCY => self::ERROR,
LogLevel::ALERT => self::ERROR,
@@ -59,12 +50,8 @@ class ConsoleLogger extends AbstractLogger
LogLevel::INFO => self::INFO,
LogLevel::DEBUG => self::INFO,
);
+ private $errored = false;
- /**
- * @param OutputInterface $output
- * @param array $verbosityLevelMap
- * @param array $formatLevelMap
- */
public function __construct(OutputInterface $output, array $verbosityLevelMap = array(), array $formatLevelMap = array())
{
$this->output = $output;
@@ -81,19 +68,34 @@ class ConsoleLogger extends AbstractLogger
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 ($this->formatLevelMap[$level] === self::ERROR && $this->output instanceof ConsoleOutputInterface) {
- $output = $this->output->getErrorOutput();
- } else {
- $output = $this->output;
+ 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</%1$s>', $this->formatLevelMap[$level], $level, $this->interpolate($message, $context)));
+ $output->writeln(sprintf('<%1$s>[%2$s] %3$s</%1$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
@@ -105,15 +107,23 @@ class ConsoleLogger extends AbstractLogger
*/
private function interpolate($message, array $context)
{
- // build a replacement array with braces around the context keys
- $replace = array();
+ if (false === strpos($message, '{')) {
+ return $message;
+ }
+
+ $replacements = array();
foreach ($context as $key => $val) {
- if (!is_array($val) && (!is_object($val) || method_exists($val, '__toString'))) {
- $replace[sprintf('{%s}', $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).']';
}
}
- // interpolate replacement values into the message and return
- return strtr($message, $replace);
+ return strtr($message, $replacements);
}
}