mirror of
https://github.com/friendica/friendica
synced 2025-04-27 10:30:10 +00:00
LegacyLoggerFactory uses Logger as factory
This commit is contained in:
parent
b40db06ef3
commit
0804413c41
6 changed files with 67 additions and 32 deletions
10
src/App.php
10
src/App.php
|
@ -146,10 +146,6 @@ class App
|
|||
|
||||
$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);
|
||||
|
@ -251,9 +247,9 @@ class App
|
|||
|
||||
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
|
||||
|
|
|
@ -9,15 +9,29 @@ declare(strict_types=1);
|
|||
|
||||
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.
|
||||
*
|
||||
|
@ -28,6 +42,8 @@ final class LegacyLoggerFactory implements LoggerFactory
|
|||
*/
|
||||
public function createLogger(string $logLevel, string $logChannel): LoggerInterface
|
||||
{
|
||||
return new NullLogger();
|
||||
$factory = new Logger($logChannel);
|
||||
|
||||
return $factory->create($this->instanceCreator, $this->config, $this->profiler);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace Friendica\Core\Logger;
|
|||
|
||||
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;
|
||||
|
@ -32,6 +33,8 @@ final class LoggerManager
|
|||
|
||||
private IManageConfigValues $config;
|
||||
|
||||
private LoggerFactory $factory;
|
||||
|
||||
private bool $debug;
|
||||
|
||||
private string $logLevel;
|
||||
|
@ -40,9 +43,10 @@ final class LoggerManager
|
|||
|
||||
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;
|
||||
|
@ -71,11 +75,11 @@ final class LoggerManager
|
|||
|
||||
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) {
|
||||
|
@ -86,9 +90,4 @@ final class LoggerManager
|
|||
|
||||
return $logger;
|
||||
}
|
||||
|
||||
private function createLogger(string $logLevel, string $logChannel): LoggerInterface
|
||||
{
|
||||
return new NullLogger();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue