Logger example


    protected function tearDown(): void
    {
        parent::tearDown();
        $connection = $this->getContainer()->get(Connection::class);
        $connection->executeStatement('DELETE FROM `log_entry`');
    }

    public function testWriteFlowEvents(): void
    {
        $handler = new TestHandler();
        $logger = new Logger('testlogger', [$handler]);

        $service = new LoggingService('test', $logger);

        $service->logFlowEvent(
            new FlowLogEvent(TestFlowBusinessEvent::EVENT_NAME, new TestFlowBusinessEvent($this->context))
        );

        $records = $handler->getRecords();

        static::assertCount(1, $records);
        $testRecord = $records[0];

        
/** * @internal * * @covers \Shopware\Core\Framework\Log\LoggerFactory */
class LoggerFactoryTest extends TestCase
{
    public function testNullLogHandler(): void
    {
        $providedHandler = [new NullHandler()];
        $mainLogger = new Logger('test_logger', $providedHandler);
        $loggerFactory = new LoggerFactory('test_case', $mainLogger);

        /** @var Logger $createdLogger */
        $createdLogger = $loggerFactory->createRotating('test_file_path');
        $usedHandler = $createdLogger->getHandlers();

        static::assertCount(1, $usedHandler);
        static::assertInstanceOf(RotatingFileHandler::classcurrent($usedHandler), 'Handler differs from excpected');
    }

    public function testRotatingFileLogHandler(): void
    {
private readonly string $rotatingFilePathPattern,
        private readonly LoggerInterface $logger,
        private readonly int $defaultFileRotationCount = 14
    ) {
    }

    /** * @param value-of<Level::VALUES>|Level $loggerLevel */
    public function createRotating(string $filePrefix, ?int $fileRotationCount = null, int|Level $loggerLevel = Level::Debug): LoggerInterface
    {
        $result = new Logger($filePrefix);
        $result->pushProcessor(new PsrLogMessageProcessor());

        /** * Use RotatingFileHandler as fallback if Nullhandler or none is given * If RotatingFileHandler is given (default configuration) -> use "default" logic for splitted logs */
        if (!method_exists($this->logger, 'getHandlers')
            || (
                \count($this->logger->getHandlers() ?? 0) === 1
                && (
                    current($this->logger->getHandlers()) instanceof NullHandler
                    
Home | Imprint | This part of the site doesn't use cookies.