]> git.mxchange.org Git - friendica.git/commitdiff
Adapt Logger\Introspection
authorPhilipp <admin@philipp.info>
Sun, 25 Dec 2022 15:48:09 +0000 (16:48 +0100)
committerPhilipp <admin@philipp.info>
Mon, 26 Dec 2022 20:18:04 +0000 (21:18 +0100)
- Create an interface
- Add it as constructor parameter

src/Core/Logger/Capabilities/IHaveCallIntrospections.php [new file with mode: 0644]
src/Core/Logger/Factory/Logger.php
src/Core/Logger/Util/Introspection.php
static/dependencies.config.php

diff --git a/src/Core/Logger/Capabilities/IHaveCallIntrospections.php b/src/Core/Logger/Capabilities/IHaveCallIntrospections.php
new file mode 100644 (file)
index 0000000..e9f27ee
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2022, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+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;
+}
index 4df7d8ecafca99c0a06b2dd2201e5c383db0364c..30e949a6815377fcdb536f87c8f00aed5a67a8ba 100644 (file)
@@ -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) {
index 83d1b6faf56a4d983c868c508cec134d71cd5481..444af2409e67474f05008f96c3dbb936cc1aa6ac 100644 (file)
 
 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);
        }
index a7de89d614b56d9dbec3f0d42c796b7e2a2d79bf..fd242c3417ad94aecac835aec12dff720225067a 100644 (file)
@@ -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'       => [