diff --git a/src/Core/Logger/Factory/LoggerFactory.php b/src/Core/Logger/Factory/LoggerFactory.php index 77c06d4f89..c789028a08 100644 --- a/src/Core/Logger/Factory/LoggerFactory.php +++ b/src/Core/Logger/Factory/LoggerFactory.php @@ -17,8 +17,14 @@ use Psr\Log\NullLogger; */ final class LoggerFactory { + private LoggerInterface $logger; + public function create(): LoggerInterface { - return new NullLogger(); + if (! isset($this->logger)) { + $this->logger = new NullLogger(); + } + + return $this->logger; } } diff --git a/tests/Unit/Core/Logger/Factory/LoggerFactoryTest.php b/tests/Unit/Core/Logger/Factory/LoggerFactoryTest.php index 71ce0c741d..1c42ec39dd 100644 --- a/tests/Unit/Core/Logger/Factory/LoggerFactoryTest.php +++ b/tests/Unit/Core/Logger/Factory/LoggerFactoryTest.php @@ -21,4 +21,11 @@ class LoggerFactoryTest extends TestCase $this->assertInstanceOf(LoggerInterface::class, $factory->create()); } + + public function testLoggerFactoryCreateReturnsSameObject(): void + { + $factory = new LoggerFactory(); + + $this->assertSame($factory->create(), $factory->create()); + } }