<commit_before><?php

namespace Scrutinizer\Cli;

use Psr\Log\AbstractLogger;
use Symfony\Component\Console\Output\OutputInterface;

class OutputLogger extends AbstractLogger
{
    private $output;
    private $verbose;

    public function __construct(OutputInterface $output, $verbose = false)
    {
        $this->output = $output;
        $this->verbose = $verbose;
    }

    public function getOutput()
    {
        return $this->output;
    }

    public function isVerbose()
    {
        return $this->verbose;
    }

    public function log($level, $message, array $context = array())
    {
        if ( ! $this->verbose && $level === 'debug') {
            return;
        }

        $map = array();
        foreach ($context as $k => $v) {
            if ( ! is_scalar($v) && $v !== null
                    && ( ! is_object($v) || ! method_exists($v, '__toString'))) {
                continue;
            }

            $map['{'.$k.'}'] = (string) $v;
        }

        $this->output->write(strtr($message, $map));
    }
}<commit_msg>swallow errors until explicitly flushed<commit_after><?php

namespace Scrutinizer\Cli;

use Psr\Log\AbstractLogger;
use Symfony\Component\Console\Output\OutputInterface;

class OutputLogger extends AbstractLogger
{
    private $output;
    private $verbose;
    private $errors = array();

    public function __construct(OutputInterface $output, $verbose = false)
    {
        $this->output = $output;
        $this->verbose = $verbose;
    }

    public function getOutput()
    {
        return $this->output;
    }

    public function isVerbose()
    {
        return $this->verbose;
    }

    public function flushErrors()
    {
        if (empty($this->errors)) {
            return;
        }

        $this->output->writeln("Errors:");
        foreach ($this->errors as $error) {
            $this->output->writeln(' - '.$error);
        }
        $this->output->write("\n");

        $this->errors = array();
    }

    public function log($level, $message, array $context = array())
    {
        if ( ! $this->verbose && $level === 'debug') {
            return;
        }

        if ($level === 'error') {
            $this->errors[] = trim($this->formatMessage($message, $context));

            return;
        }

        $this->output->write($this->formatMessage($message, $context));
    }

    private function formatMessage($message, array $context)
    {
        $map = array();
        foreach ($context as $k => $v) {
            if ( ! is_scalar($v) && $v !== null
                && ( ! is_object($v) || ! method_exists($v, '__toString'))) {
                continue;
            }

            $map['{'.$k.'}'] = (string) $v;
        }

        return strtr($message, $map);
    }
}
{'fraction_non_alphanumeric': 0.15827598696124592, 'fraction_numerical': 0.0, 'mean_word_length': 1.9924160346695559, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '913671', 'n_tokens_mistral': 822, 'n_tokens_neox': 795, 'n_words': 172}