<commit_before><?php

namespace Monolog\Handler;

use RollbarNotifier;
use Exception;

/**
 * Sends errors to Rollbar
 *
 * @author <NAME> <<EMAIL>>
 */
class RollbarHandler extends AbstractProcessingHandler
{
    /**
     * Rollbar notifier
     *
     * @var RollbarNotifier
     */
    protected $rollbarNotifier;

    /**
     * @param RollbarNotifier  $rollbarNotifier RollbarNotifier object constructed with valid token
     * @param integer          $level           The minimum logging level at which this handler will be triggered
     * @param boolean          $bubble          Whether the messages that are handled can bubble up the stack or not
     */
    public function __construct(RollbarNotifier $rollbarNotifier, $level = Logger::ERROR, $bubble = true)
    {
        $this->rollbarNotifier = $rollbarNotifier;

        parent::__construct($level, $bubble);
    }

    protected function write(array $record)
    {
        if (isset($record['context']['exception']) && $record['context']['exception'] instanceof Exception) {
            $this->rollbarNotifier->report_exception($record['context']['exception']);
        } else {
            $this->rollbarNotifier->report_message(
                $record['message'],
                $record['level_name'],
                $record['extra']
            );
        }
    }

    public function __destruct()
    {
        $this->rollbarNotifier->flush();
    }
}<commit_msg>Flush roll bar notifier on close rather than destruct.<commit_after><?php

namespace Monolog\Handler;

use RollbarNotifier;
use Exception;

/**
 * Sends errors to Rollbar
 *
 * @author <NAME> <<EMAIL>>
 */
class RollbarHandler extends AbstractProcessingHandler
{
    /**
     * Rollbar notifier
     *
     * @var RollbarNotifier
     */
    protected $rollbarNotifier;

    /**
     * @param RollbarNotifier  $rollbarNotifier RollbarNotifier object constructed with valid token
     * @param integer          $level           The minimum logging level at which this handler will be triggered
     * @param boolean          $bubble          Whether the messages that are handled can bubble up the stack or not
     */
    public function __construct(RollbarNotifier $rollbarNotifier, $level = Logger::ERROR, $bubble = true)
    {
        $this->rollbarNotifier = $rollbarNotifier;

        parent::__construct($level, $bubble);
    }

    /**
     * {@inheritdoc}
     */
    protected function write(array $record)
    {
        if (isset($record['context']['exception']) && $record['context']['exception'] instanceof Exception) {
            $this->rollbarNotifier->report_exception($record['context']['exception']);
        } else {
            $this->rollbarNotifier->report_message(
                $record['message'],
                $record['level_name'],
                $record['extra']
            );
        }
    }

    /**
     * {@inheritdoc}
     */
    public function close()
    {
        $this->rollbarNotifier->flush();
    }
}
{'fraction_non_alphanumeric': 0.11695710455764075, 'fraction_numerical': 0.0, 'mean_word_length': 2.4468822170900695, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 23, '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': '2750446', 'n_tokens_mistral': 801, 'n_tokens_neox': 786, 'n_words': 198}