From: Philipp Date: Sun, 25 Dec 2022 15:48:09 +0000 (+0100) Subject: Adapt Logger\Introspection X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=10864e50c722ba73afd013e41d90aaa497ea6300;p=friendica.git Adapt Logger\Introspection - Create an interface - Add it as constructor parameter --- diff --git a/src/Core/Logger/Capabilities/IHaveCallIntrospections.php b/src/Core/Logger/Capabilities/IHaveCallIntrospections.php new file mode 100644 index 0000000000..e9f27ee1ad --- /dev/null +++ b/src/Core/Logger/Capabilities/IHaveCallIntrospections.php @@ -0,0 +1,52 @@ +. + * + */ + +namespace Friendica\Core\Logger\Capabilities; +use Friendica\Core\Logger\Factory\Logger; +use Friendica\Util\Profiler; + +interface IHaveCallIntrospections +{ + /** + * A list of classes, which shouldn't get logged + * + * @var string[] + */ + public const IGNORE_CLASS_LIST = [ + Logger::class, + Profiler::class, + 'Friendica\\Core\\Logger\\Type', + ]; + + /** + * Adds new classes to get skipped + * + * @param array $classNames + */ + public function addClasses(array $classNames): void; + + /** + * Returns the introspection record of the current call + * + * @return array + */ + public function getRecord(): array; +} diff --git a/src/Core/Logger/Factory/Logger.php b/src/Core/Logger/Factory/Logger.php index 4df7d8ecaf..30e949a681 100644 --- a/src/Core/Logger/Factory/Logger.php +++ b/src/Core/Logger/Factory/Logger.php @@ -23,11 +23,11 @@ namespace Friendica\Core\Logger\Factory; use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\Core; +use Friendica\Core\Logger\Capabilities\IHaveCallIntrospections; use Friendica\Core\Logger\Exception\LogLevelException; use Friendica\Database\Database; use Friendica\Network\HTTPException\InternalServerErrorException; use Friendica\Util\FileSystem; -use Friendica\Core\Logger\Util\Introspection; use Friendica\Core\Logger\Type\ProfilerLogger; use Friendica\Core\Logger\Type\StreamLogger; use Friendica\Core\Logger\Type\SyslogLogger; @@ -43,17 +43,6 @@ class Logger { const DEV_CHANNEL = 'dev'; - /** - * A list of classes, which shouldn't get logged - * - * @var string[] - */ - private static $ignoreClassList = [ - Core\Logger::class, - Profiler::class, - 'Friendica\\Core\\Logger\\Type', - ]; - /** @var string The log-channel (app, worker, ...) */ private $channel; @@ -79,7 +68,7 @@ class Logger * * @return LoggerInterface The PSR-3 compliant logger instance */ - public function create(Database $database, IManageConfigValues $config, Profiler $profiler, FileSystem $fileSystem, ?string $minLevel = null): LoggerInterface + public function create(Database $database, IManageConfigValues $config, Profiler $profiler, FileSystem $fileSystem, IHaveCallIntrospections $introspection, ?string $minLevel = null): LoggerInterface { if (empty($config->get('system', 'debugging', false))) { $logger = new NullLogger(); @@ -87,7 +76,6 @@ class Logger return $logger; } - $introspection = new Introspection(self::$ignoreClassList); $minLevel = $minLevel ?? $config->get('system', 'loglevel'); $loglevel = self::mapLegacyConfigDebugLevel((string)$minLevel); @@ -99,7 +87,7 @@ class Logger $logger = new SyslogLogger($this->channel, $introspection, $loglevel, $config->get('system', 'syslog_flags', SyslogLogger::DEFAULT_FLAGS), $config->get('system', 'syslog_facility', SyslogLogger::DEFAULT_FACILITY)); } catch (LogLevelException $exception) { // If there's a wrong config value for loglevel, try again with standard - $logger = $this->create($database, $config, $profiler, $fileSystem, LogLevel::NOTICE); + $logger = $this->create($database, $config, $profiler, $fileSystem, $introspection, LogLevel::NOTICE); $logger->warning('Invalid loglevel set in config.', ['loglevel' => $loglevel]); } catch (\Throwable $e) { // No logger ... @@ -134,7 +122,7 @@ class Logger $logger = new StreamLogger($this->channel, $stream, $introspection, $fileSystem, $loglevel); } catch (LogLevelException $exception) { // If there's a wrong config value for loglevel, try again with standard - $logger = $this->create($database, $config, $profiler, $fileSystem, LogLevel::NOTICE); + $logger = $this->create($database, $config, $profiler, $fileSystem, $introspection, LogLevel::NOTICE); $logger->warning('Invalid loglevel set in config.', ['loglevel' => $loglevel]); } catch (\Throwable $t) { // No logger ... @@ -145,7 +133,7 @@ class Logger $logger = new SyslogLogger($this->channel, $introspection, $loglevel); } catch (LogLevelException $exception) { // If there's a wrong config value for loglevel, try again with standard - $logger = $this->create($database, $config, $profiler, $fileSystem, LogLevel::NOTICE); + $logger = $this->create($database, $config, $profiler, $fileSystem, $introspection, LogLevel::NOTICE); $logger->warning('Invalid loglevel set in config.', ['loglevel' => $loglevel]); } catch (\Throwable $e) { // No logger ... @@ -182,7 +170,7 @@ class Logger * @return LoggerInterface The PSR-3 compliant logger instance * @throws \Exception */ - public static function createDev(IManageConfigValues $config, Profiler $profiler, FileSystem $fileSystem) + public static function createDev(IManageConfigValues $config, Profiler $profiler, FileSystem $fileSystem, IHaveCallIntrospections $introspection) { $debugging = $config->get('system', 'debugging'); $stream = $config->get('system', 'dlogfile'); @@ -193,8 +181,6 @@ class Logger return new NullLogger(); } - $introspection = new Introspection(self::$ignoreClassList); - $name = $config->get('system', 'logger_config', 'stream'); switch ($name) { diff --git a/src/Core/Logger/Util/Introspection.php b/src/Core/Logger/Util/Introspection.php index 83d1b6faf5..444af2409e 100644 --- a/src/Core/Logger/Util/Introspection.php +++ b/src/Core/Logger/Util/Introspection.php @@ -21,10 +21,12 @@ namespace Friendica\Core\Logger\Util; +use Friendica\Core\Logger\Capabilities\IHaveCallIntrospections; + /** * Get Introspection information about the current call */ -class Introspection +class Introspection implements IHaveCallIntrospections { /** @var int */ private $skipStackFramesCount; @@ -52,7 +54,7 @@ class Introspection * * @param array $classNames */ - public function addClasses(array $classNames) + public function addClasses(array $classNames): void { $this->skipClassesPartials = array_merge($this->skipClassesPartials, $classNames); } diff --git a/static/dependencies.config.php b/static/dependencies.config.php index a7de89d614..fd242c3417 100644 --- a/static/dependencies.config.php +++ b/static/dependencies.config.php @@ -176,6 +176,12 @@ return [ ['createDev', [], Dice::CHAIN_CALL], ] ], + \Friendica\Core\Logger\Capabilities\IHaveCallIntrospections::class => [ + 'instanceOf' => \Friendica\Core\Logger\Util\Introspection::class, + 'constructParams' => [ + \Friendica\Core\Logger\Util\Introspection::IGNORE_CLASS_LIST, + ], + ], Cache\Capability\ICanCache::class => [ 'instanceOf' => Cache\Factory\Cache::class, 'call' => [