pushHandler example

public function onStartDispatch($args)
    {
        $parameters = $this->get('service_container')->getParameter('shopware.errorhandler');

        $this->throwOnRecoverableError = $parameters['throwOnRecoverableError'];
        $this->ignoredExceptionClasses = $parameters['ignoredExceptionClasses'];

        // Register ErrorHandler for all errors, including strict         $this->registerErrorHandler(E_ALL | E_STRICT);

        if ($this->Config()->get('logMail')) {
            $this->get('corelogger')->pushHandler($this->createMailHandler());
        }

        $this->get('events')->addListener(
            'Enlight_Controller_Front_DispatchLoopShutdown',
            [$this, 'onDispatchLoopShutdown']
        );
    }

    /** * Register error handler callback * * @see http://www.php.net/manual/en/function.set-error-handler.php Custom error handler * * @param int $errorLevel * * @return Shopware_Plugins_Core_ErrorHandler_Bootstrap */

        if (!method_exists($this->logger, 'getHandlers')
            || (
                \count($this->logger->getHandlers() ?? 0) === 1
                && (
                    current($this->logger->getHandlers()) instanceof NullHandler
                    || current($this->logger->getHandlers()) instanceof RotatingFileHandler
                )
            )
        ) {
            $filepath = sprintf($this->rotatingFilePathPattern, $filePrefix);
            $result->pushHandler(new RotatingFileHandler($filepath$fileRotationCount ?? $this->defaultFileRotationCount, $loggerLevel));

            return $result;
        }

        $result->setHandlers($this->logger->getHandlers());

        return $result;
    }
}
$this->assertTrue($handler->handle($infoRecord), 'The handler finished handling the log as bubble is false.');
    }

    public function testLogsFromListeners()
    {
        $output = new BufferedOutput();
        $output->setVerbosity(OutputInterface::VERBOSITY_DEBUG);

        $handler = new ConsoleHandler(null, false);

        $logger = new Logger('app');
        $logger->pushHandler($handler);

        $dispatcher = new EventDispatcher();
        $dispatcher->addListener(ConsoleEvents::COMMAND, function D) use ($logger) {
            $logger->info('Before command message.');
        });
        $dispatcher->addListener(ConsoleEvents::TERMINATE, function D) use ($logger) {
            $logger->info('Before terminate message.');
        });

        $dispatcher->addSubscriber($handler);

        
'documentRangerType' => $documentRangerType,
        ]);

        static::assertEmpty($this->getDocumentId($order->getId()));

        if ($documentType === CreditNoteRenderer::TYPE) {
            $this->addCreditItemToVersionedOrder($order->getId()$context);
        }

        $handler = new TestHandler(Level::Error);

        $this->logger->pushHandler($handler);

        /** @var FlowFactory $flowFactory */
        $flowFactory = $this->getContainer()->get(FlowFactory::class);
        $flow = $flowFactory->create($event);
        $flow->setConfig($config);

        $subscriber->handleFlow($flow);

        static::assertNotEmpty($handler->getRecords());
        static::assertNotEmpty($record = $handler->getRecords()[0]);
        static::assertEquals(
            
Home | Imprint | This part of the site doesn't use cookies.