$this->registerErrorHandler();
- /** @var LoggerManager */
- $loggerManager = $this->container->create(LoggerManager::class);
- $loggerManager->changeLogChannel(LogChannel::APP);
-
$this->requestId = $this->container->create(Request::class)->getRequestId();
$this->auth = $this->container->create(Authentication::class);
$this->config = $this->container->create(IManageConfigValues::class);
private function setupContainerForLogger(string $logChannel): void
{
- $this->container->addRule(LoggerInterface::class, [
- 'constructParams' => [$logChannel],
- ]);
+ /** @var LoggerManager */
+ $loggerManager = $this->container->create(LoggerManager::class);
+ $loggerManager->changeLogChannel($logChannel);
}
private function setupLegacyServiceLocator(): void
namespace Friendica\Core\Logger\Factory;
+use Friendica\Core\Config\Capability\IManageConfigValues;
+use Friendica\Core\Hooks\Capability\ICanCreateInstances;
+use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface;
-use Psr\Log\LogLevel;
-use Psr\Log\NullLogger;
/**
* Manager for the core logging instances
*/
final class LegacyLoggerFactory implements LoggerFactory
{
+ private ICanCreateInstances $instanceCreator;
+
+ private IManageConfigValues $config;
+
+ private Profiler $profiler;
+
+ public function __construct(ICanCreateInstances $instanceCreator, IManageConfigValues $config, Profiler $profiler)
+ {
+ $this->instanceCreator = $instanceCreator;
+ $this->config = $config;
+ $this->profiler = $profiler;
+ }
+
/**
* Creates and returns a PSR-3 Logger instance.
*
*/
public function createLogger(string $logLevel, string $logChannel): LoggerInterface
{
- return new NullLogger();
+ $factory = new Logger($logChannel);
+
+ return $factory->create($this->instanceCreator, $this->config, $this->profiler);
}
}
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Logger\Capability\LogChannel;
+use Friendica\Core\Logger\Factory\LoggerFactory;
use Friendica\Core\Logger\Type\ProfilerLogger;
use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface;
private IManageConfigValues $config;
+ private LoggerFactory $factory;
+
private bool $debug;
private string $logLevel;
private string $logChannel;
- public function __construct(IManageConfigValues $config)
+ public function __construct(IManageConfigValues $config, LoggerFactory $factory)
{
- $this->config = $config;
+ $this->config = $config;
+ $this->factory = $factory;
$this->debug = (bool) $config->get('system', 'debugging') ?? false;
$this->logLevel = (string) $config->get('system', 'loglevel') ?? LogLevel::NOTICE;
private function createProfiledLogger(): LoggerInterface
{
- // Always return NullLogger if debug is disabled
+ // Always create NullLogger if debug is disabled
if ($this->debug === false) {
$logger = new NullLogger();
} else {
- $logger = $this->createLogger($this->logLevel, $this->logChannel);
+ $logger = $this->factory->createLogger($this->logLevel, $this->logChannel);
}
if ($this->profiling === true) {
return $logger;
}
-
- private function createLogger(string $logLevel, string $logChannel): LoggerInterface
- {
- return new NullLogger();
- }
}
],
],
\Psr\Log\LoggerInterface::class => [
- 'instanceOf' => \Friendica\Core\Logger\Factory\Logger::class,
- 'call' => [
- ['create', [], Dice::CHAIN_CALL],
- ],
- ],
- '$LoggerInterface' => [
- 'shared' => false,
'instanceOf' => \Friendica\Core\Logger\LoggerManager::class,
'call' => [
['getLogger', [], Dice::CHAIN_CALL],
],
],
+ \Friendica\Core\Logger\LoggerManager::class => [
+ 'substitutions' => [
+ \Friendica\Core\Logger\Factory\LoggerFactory::class => \Friendica\Core\Logger\Factory\LegacyLoggerFactory::class,
+ ],
+ ],
+ \Friendica\Core\Logger\Factory\LoggerFactory::class => [
+ 'instanceOf' => \Friendica\Core\Logger\Factory\LegacyLoggerFactory::class,
+ ],
\Friendica\Core\Logger\Type\SyslogLogger::class => [
'instanceOf' => \Friendica\Core\Logger\Factory\SyslogLogger::class,
'call' => [
namespace Friendica\Test\Unit\Core\Logger\Factory;
+use Friendica\Core\Config\Capability\IManageConfigValues;
+use Friendica\Core\Hooks\Capability\ICanCreateInstances;
use Friendica\Core\Logger\Capability\LogChannel;
use Friendica\Core\Logger\Factory\LegacyLoggerFactory;
+use Friendica\Util\Profiler;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
{
public function testCreateLoggerReturnsPsrLogger(): void
{
- $factory = new LegacyLoggerFactory();
+ $factory = new LegacyLoggerFactory(
+ $this->createStub(ICanCreateInstances::class),
+ $this->createStub(IManageConfigValues::class),
+ $this->createStub(Profiler::class),
+ );
$this->assertInstanceOf(
LoggerInterface::class,
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Logger\Capability\LogChannel;
+use Friendica\Core\Logger\Factory\LoggerFactory;
use Friendica\Core\Logger\LoggerManager;
use Friendica\Core\Logger\Type\ProfilerLogger;
use PHPUnit\Framework\TestCase;
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue(null, null);
- $factory = new LoggerManager($this->createStub(IManageConfigValues::class));
+ $factory = new LoggerManager(
+ $this->createStub(IManageConfigValues::class),
+ $this->createStub(LoggerFactory::class)
+ );
$this->assertInstanceOf(LoggerInterface::class, $factory->getLogger());
}
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue(null, null);
- $factory = new LoggerManager($this->createStub(IManageConfigValues::class));
+ $factory = new LoggerManager(
+ $this->createStub(IManageConfigValues::class),
+ $this->createStub(LoggerFactory::class)
+ );
$this->assertSame($factory->getLogger(), $factory->getLogger());
}
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue(null, null);
- $factory = new LoggerManager($config);
+ $factory = new LoggerManager(
+ $config,
+ $this->createStub(LoggerFactory::class)
+ );
$this->assertInstanceOf(NullLogger::class, $factory->getLogger());
}
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue(null, null);
- $factory = new LoggerManager($config);
+ $factory = new LoggerManager(
+ $config,
+ $this->createStub(LoggerFactory::class)
+ );
$this->assertInstanceOf(ProfilerLogger::class, $factory->getLogger());
}
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue(null, null);
- $factory = new LoggerManager($config);
+ $factory = new LoggerManager(
+ $config,
+ $this->createStub(LoggerFactory::class)
+ );
$logger1 = $factory->getLogger();