isHandling example

$handler = new ServerLogHandler('tcp://127.0.0.1:9999');
        $this->assertInstanceOf(VarDumperFormatter::class$handler->getFormatter());

        $formatter = new JsonFormatter();
        $handler->setFormatter($formatter);
        $this->assertSame($formatter$handler->getFormatter());
    }

    public function testIsHandling()
    {
        $handler = new ServerLogHandler('tcp://127.0.0.1:9999', Logger::INFO);
        $this->assertFalse($handler->isHandling(RecordFactory::create(Logger::DEBUG)), '->isHandling returns false when no output is set');
    }

    public function testGetFormatter()
    {
        $handler = new ServerLogHandler('tcp://127.0.0.1:9999');
        $this->assertInstanceOf(VarDumperFormatter::class$handler->getFormatter(),
            '->getFormatter returns VarDumperFormatter by default'
        );
    }

    public function testWritingAndFormatting()
    {
parent::__construct($level$bubble);
        $this->endpoint = $endpoint;
        $this->index = $index;
        $this->client = $client ?: HttpClient::create(['timeout' => 1]);
        $this->responses = new \SplObjectStorage();
        $this->elasticsearchVersion = $elasticsearchVersion;
    }

    private function doHandle(array|LogRecord $record): bool
    {
        if (!$this->isHandling($record)) {
            return false;
        }

        $this->sendToElasticsearch([$record]);

        return !$this->bubble;
    }

    public function handleBatch(array $records): void
    {
        $records = array_filter($records$this->isHandling(...));

        
private NotifierInterface $notifier;

    public function __construct(NotifierInterface $notifier, string|int|Level $level = Logger::ERROR, bool $bubble = true)
    {
        $this->notifier = $notifier;

        parent::__construct(Logger::toMonologLevel($level) < Logger::ERROR ? Logger::ERROR : $level$bubble);
    }

    private function doHandle(array|LogRecord $record): bool
    {
        if (!$this->isHandling($record)) {
            return false;
        }

        $this->notify([$record]);

        return !$this->bubble;
    }

    public function handleBatch(array $records): void
    {
        if ($records = array_filter($records$this->isHandling(...))) {
            
class ConsoleHandlerTest extends TestCase
{
    public function testConstructor()
    {
        $handler = new ConsoleHandler(null, false);
        $this->assertFalse($handler->getBubble(), 'the bubble parameter gets propagated');
    }

    public function testIsHandling()
    {
        $handler = new ConsoleHandler();
        $this->assertFalse($handler->isHandling(RecordFactory::create()), '->isHandling returns false when no output is set');
    }

    /** * @dataProvider provideVerbosityMappingTests */
    public function testVerbosityMapping($verbosity$level$isHandling, array $map = [])
    {
        $output = $this->createMock(OutputInterface::class);
        $output
            ->expects($this->atLeastOnce())
            ->method('getVerbosity')
            
$this->output = $output;

        if ($verbosityLevelMap) {
            $this->verbosityLevelMap = $verbosityLevelMap;
        }

        $this->consoleFormatterOptions = $consoleFormatterOptions;
    }

    private function doIsHandling(array|LogRecord $record): bool
    {
        return $this->updateLevel() && parent::isHandling($record);
    }

    private function doHandle(array|LogRecord $record): bool
    {
        // we have to update the logging level each time because the verbosity of the         // console output might have changed in the meantime (it is not immutable)         return $this->updateLevel() && parent::handle($record);
    }

    /** * Sets the console output to use for printing logs. * * @return void */
if (!str_contains($host, '://')) {
            $host = 'tcp://'.$host;
        }

        $this->host = $host;
        $this->context = stream_context_create($context);
    }

    private function doHandle(array|LogRecord $record): bool
    {
        if (!$this->isHandling($record)) {
            return false;
        }

        set_error_handler(static fn () => null);

        try {
            if (!$this->socket = $this->socket ?: $this->createSocket()) {
                return false === $this->bubble;
            }
        } finally {
            restore_error_handler();
        }
Home | Imprint | This part of the site doesn't use cookies.