Rename LoggerFactory into LoggerManager

This commit is contained in:
Art4 2025-01-10 15:21:56 +00:00
parent c339dc1a07
commit 2df76617c1
3 changed files with 66 additions and 63 deletions

View file

@ -7,7 +7,7 @@
declare(strict_types=1); declare(strict_types=1);
namespace Friendica\Core\Logger\Factory; namespace Friendica\Core\Logger;
use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Logger\Capability\LogChannel; use Friendica\Core\Logger\Capability\LogChannel;
@ -18,9 +18,9 @@ use Psr\Log\LogLevel;
use Psr\Log\NullLogger; use Psr\Log\NullLogger;
/** /**
* The logger factory for the core logging instances * Manager for the core logging instances
*/ */
final class LoggerFactory final class LoggerManager
{ {
private IManageConfigValues $config; private IManageConfigValues $config;
@ -44,7 +44,10 @@ final class LoggerFactory
$this->profiling = (bool) $config->get('system', 'profiling') ?? false; $this->profiling = (bool) $config->get('system', 'profiling') ?? false;
} }
public function create(): LoggerInterface /**
* (Creates and) Returns the logger instance
*/
public function getLogger(): LoggerInterface
{ {
if (! isset($this->logger)) { if (! isset($this->logger)) {
$this->logger = $this->createProfiledLogger(); $this->logger = $this->createProfiledLogger();

View file

@ -1,59 +0,0 @@
<?php
// Copyright (C) 2010-2024, the Friendica project
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
//
// SPDX-License-Identifier: AGPL-3.0-or-later
declare(strict_types=1);
namespace Friendica\Test\Unit\Core\Logger\Factory;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Logger\Factory\LoggerFactory;
use Friendica\Core\Logger\Type\ProfilerLogger;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
class LoggerFactoryTest extends TestCase
{
public function testCreateReturnsPsrLogger(): void
{
$factory = new LoggerFactory($this->createStub(IManageConfigValues::class));
$this->assertInstanceOf(LoggerInterface::class, $factory->create());
}
public function testCreateReturnsSameObject(): void
{
$factory = new LoggerFactory($this->createStub(IManageConfigValues::class));
$this->assertSame($factory->create(), $factory->create());
}
public function testCreateWithDebugDisabledReturnsNullLogger(): void
{
$config = $this->createStub(IManageConfigValues::class);
$config->method('get')->willReturnMap([
['system', 'debugging', null, false],
]);
$factory = new LoggerFactory($config);
$this->assertInstanceOf(NullLogger::class, $factory->create());
}
public function testCreateWithProfilerEnabledReturnsProfilerLogger(): void
{
$config = $this->createStub(IManageConfigValues::class);
$config->method('get')->willReturnMap([
['system', 'debugging', null, false],
['system', 'profiling', null, true],
]);
$factory = new LoggerFactory($config);
$this->assertInstanceOf(ProfilerLogger::class, $factory->create());
}
}

View file

@ -0,0 +1,59 @@
<?php
// Copyright (C) 2010-2024, the Friendica project
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
//
// SPDX-License-Identifier: AGPL-3.0-or-later
declare(strict_types=1);
namespace Friendica\Test\Unit\Core\Logger;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Logger\LoggerManager;
use Friendica\Core\Logger\Type\ProfilerLogger;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
class LoggerManagerTest extends TestCase
{
public function testGetLoggerReturnsPsrLogger(): void
{
$factory = new LoggerManager($this->createStub(IManageConfigValues::class));
$this->assertInstanceOf(LoggerInterface::class, $factory->getLogger());
}
public function testGetLoggerReturnsSameObject(): void
{
$factory = new LoggerManager($this->createStub(IManageConfigValues::class));
$this->assertSame($factory->getLogger(), $factory->getLogger());
}
public function testGetLoggerWithDebugDisabledReturnsNullLogger(): void
{
$config = $this->createStub(IManageConfigValues::class);
$config->method('get')->willReturnMap([
['system', 'debugging', null, false],
]);
$factory = new LoggerManager($config);
$this->assertInstanceOf(NullLogger::class, $factory->getLogger());
}
public function testGetLoggerWithProfilerEnabledReturnsProfilerLogger(): void
{
$config = $this->createStub(IManageConfigValues::class);
$config->method('get')->willReturnMap([
['system', 'debugging', null, false],
['system', 'profiling', null, true],
]);
$factory = new LoggerManager($config);
$this->assertInstanceOf(ProfilerLogger::class, $factory->getLogger());
}
}