RotatingFileHandler example


        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;
    }
}
/** @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
    {
        $providedHandler = [new RotatingFileHandler('test')];
        $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');
    }

    
Home | Imprint | This part of the site doesn't use cookies.