]> git.mxchange.org Git - friendica.git/commitdiff
Move Introspection to Logger package
authorPhilipp <admin@philipp.info>
Fri, 29 Oct 2021 10:36:14 +0000 (12:36 +0200)
committerPhilipp <admin@philipp.info>
Fri, 29 Oct 2021 10:37:22 +0000 (12:37 +0200)
src/Core/Logger/Factory/Logger.php
src/Core/Logger/Type/AbstractLogger.php
src/Core/Logger/Type/Monolog/IntrospectionProcessor.php
src/Core/Logger/Type/StreamLogger.php
src/Core/Logger/Type/SyslogLogger.php
src/Core/Logger/Util/Introspection.php [new file with mode: 0644]
src/Util/Introspection.php [deleted file]
tests/src/Core/Logger/AbstractLoggerTest.php
tests/src/Core/Logger/SyslogLoggerWrapper.php

index f9b32d93282a718e4124369e5b27f3f564a49140..8f555483c80a8cb6979d64354e0a7b009b70e707 100644 (file)
@@ -27,7 +27,7 @@ use Friendica\Core;
 use Friendica\Core\Logger\Exception\LogLevelException;
 use Friendica\Database\Database;
 use Friendica\Util\FileSystem;
-use Friendica\Util\Introspection;
+use Friendica\Core\Logger\Util\Introspection;
 use Friendica\Core\Logger\Type\Monolog\DevelopHandler;
 use Friendica\Core\Logger\Type\Monolog\IntrospectionProcessor;
 use Friendica\Core\Logger\Type\ProfilerLogger;
index 0b6d9f38fd7a0a40bc48b5224f0cf7795d14c0de..e26f1705d4d2ceb0b1a095da5507f5993992f958 100644 (file)
@@ -22,7 +22,7 @@
 namespace Friendica\Core\Logger\Type;
 
 use Friendica\Core\Logger\Exception\LoggerException;
-use Friendica\Util\Introspection;
+use Friendica\Core\Logger\Util\Introspection;
 use Friendica\Util\Strings;
 use Psr\Log\LoggerInterface;
 use Psr\Log\LogLevel;
index 756331b22f3710acc28067377776b3483999ddb7..9da48ff36ac030d161e538bd3560ab539040040f 100644 (file)
@@ -21,7 +21,7 @@
 
 namespace Friendica\Core\Logger\Type\Monolog;
 
-use Friendica\Util\Introspection;
+use Friendica\Core\Logger\Util\Introspection;
 use Monolog\Logger;
 use Monolog\Processor\ProcessorInterface;
 
index f67aef9a49996e8e97b6bb2e2fe3e3ede6cee3db..8d4d8b577e4705a64e423bfe6f71808fa2e38877 100644 (file)
@@ -26,7 +26,7 @@ use Friendica\Core\Logger\Exception\LoggerException;
 use Friendica\Core\Logger\Exception\LogLevelException;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\FileSystem;
-use Friendica\Util\Introspection;
+use Friendica\Core\Logger\Util\Introspection;
 use Psr\Log\LogLevel;
 
 /**
index 024d47b3129efae6b14a4f8f903268de1234c0e3..54cb327951323a5310e3a038c93cc779fbfd6130 100644 (file)
@@ -23,7 +23,7 @@ namespace Friendica\Core\Logger\Type;
 
 use Friendica\Core\Logger\Exception\LoggerException;
 use Friendica\Core\Logger\Exception\LogLevelException;
-use Friendica\Util\Introspection;
+use Friendica\Core\Logger\Util\Introspection;
 use Psr\Log\LogLevel;
 
 /**
diff --git a/src/Core/Logger/Util/Introspection.php b/src/Core/Logger/Util/Introspection.php
new file mode 100644 (file)
index 0000000..7c2040b
--- /dev/null
@@ -0,0 +1,110 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2021, 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\Util;
+
+/**
+ * Get Introspection information about the current call
+ */
+class Introspection
+{
+       /** @var int  */
+       private $skipStackFramesCount;
+
+       /** @var string[] */
+       private $skipClassesPartials;
+
+       private $skipFunctions = [
+               'call_user_func',
+               'call_user_func_array',
+       ];
+
+       /**
+        * @param string[] $skipClassesPartials  An array of classes to skip during logging
+        * @param int      $skipStackFramesCount If the logger should use information from other hierarchy levels of the call
+        */
+       public function __construct(array $skipClassesPartials = [], int $skipStackFramesCount = 0)
+       {
+               $this->skipClassesPartials  = $skipClassesPartials;
+               $this->skipStackFramesCount = $skipStackFramesCount;
+       }
+
+       /**
+        * Adds new classes to get skipped
+        *
+        * @param array $classNames
+        */
+       public function addClasses(array $classNames)
+       {
+               $this->skipClassesPartials = array_merge($this->skipClassesPartials, $classNames);
+       }
+
+       /**
+        * Returns the introspection record of the current call
+        *
+        * @return array
+        */
+       public function getRecord(): array
+       {
+               $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
+
+               $i = 1;
+
+               while ($this->isTraceClassOrSkippedFunction($trace, $i)) {
+                       $i++;
+               }
+
+               $i += $this->skipStackFramesCount;
+
+               return [
+                       'file'     => isset($trace[$i - 1]['file']) ? basename($trace[$i - 1]['file']) : null,
+                       'line'     => $trace[$i - 1]['line'] ?? null,
+                       'function' => $trace[$i]['function'] ?? null,
+               ];
+       }
+
+       /**
+        * Checks if the current trace class or function has to be skipped
+        *
+        * @param array $trace The current trace array
+        * @param int   $index The index of the current hierarchy level
+        *
+        * @return bool True if the class or function should get skipped, otherwise false
+        */
+       private function isTraceClassOrSkippedFunction(array $trace, int $index): bool
+       {
+               if (!isset($trace[$index])) {
+                       return false;
+               }
+
+               if (isset($trace[$index]['class'])) {
+                       foreach ($this->skipClassesPartials as $part) {
+                               if (strpos($trace[$index]['class'], $part) !== false) {
+                                       return true;
+                               }
+                       }
+               } elseif (in_array($trace[$index]['function'], $this->skipFunctions)) {
+                       return true;
+               }
+
+               return false;
+       }
+}
diff --git a/src/Util/Introspection.php b/src/Util/Introspection.php
deleted file mode 100644 (file)
index 540bfea..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-<?php
-/**
- * @copyright Copyright (C) 2010-2021, 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\Util;
-
-/**
- * Get Introspection information about the current call
- */
-class Introspection
-{
-       private $skipStackFramesCount;
-
-       private $skipClassesPartials;
-
-       private $skipFunctions = [
-               'call_user_func',
-               'call_user_func_array',
-       ];
-
-       /**
-        * @param array $skipClassesPartials  An array of classes to skip during logging
-        * @param int   $skipStackFramesCount If the logger should use information from other hierarchy levels of the call
-        */
-       public function __construct($skipClassesPartials = array(), $skipStackFramesCount = 0)
-       {
-               $this->skipClassesPartials  = $skipClassesPartials;
-               $this->skipStackFramesCount = $skipStackFramesCount;
-       }
-
-       /**
-        * Adds new classes to get skipped
-        * @param array $classNames
-        */
-       public function addClasses(array $classNames)
-       {
-               $this->skipClassesPartials = array_merge($this->skipClassesPartials, $classNames);
-       }
-
-       /**
-        * Returns the introspection record of the current call
-        *
-        * @return array
-        */
-       public function getRecord()
-       {
-               $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
-
-               $i = 1;
-
-               while ($this->isTraceClassOrSkippedFunction($trace, $i)) {
-                       $i++;
-               }
-
-               $i += $this->skipStackFramesCount;
-
-               return [
-                       'file'     => isset($trace[$i - 1]['file']) ? basename($trace[$i - 1]['file']) : null,
-                       'line'     => isset($trace[$i - 1]['line']) ? $trace[$i - 1]['line'] : null,
-                       'function' => isset($trace[$i]['function']) ? $trace[$i]['function'] : null,
-               ];
-       }
-
-       /**
-        * Checks if the current trace class or function has to be skipped
-        *
-        * @param array $trace The current trace array
-        * @param int   $index The index of the current hierarchy level
-        *
-        * @return bool True if the class or function should get skipped, otherwise false
-        */
-       private function isTraceClassOrSkippedFunction(array $trace, $index)
-       {
-               if (!isset($trace[$index])) {
-                       return false;
-               }
-
-               if (isset($trace[$index]['class'])) {
-                       foreach ($this->skipClassesPartials as $part) {
-                               if (strpos($trace[$index]['class'], $part) !== false) {
-                                       return true;
-                               }
-                       }
-               } elseif (in_array($trace[$index]['function'], $this->skipFunctions)) {
-                       return true;
-               }
-
-               return false;
-       }
-}
index f1a05531027caef21ffb39391824cf4f7aae1508..2734158b5c7cc078e4b45cbcea5cf8307f188127 100644 (file)
@@ -22,7 +22,7 @@
 namespace Friendica\Test\src\Core\Logger;
 
 use Friendica\Test\MockedTest;
-use Friendica\Util\Introspection;
+use Friendica\Core\Logger\Util\Introspection;
 use Mockery\MockInterface;
 use Psr\Log\LoggerInterface;
 use Psr\Log\LogLevel;
index 05dcbd6bc5a2635b729491264e9900ca2a1dca5d..92d71f80a1ccacc4370514c8859de90e9eec7508 100644 (file)
@@ -22,7 +22,7 @@
 namespace Friendica\Test\src\Core\Logger;
 
 use Friendica\Core\Logger\Type\SyslogLogger;
-use Friendica\Util\Introspection;
+use Friendica\Core\Logger\Util\Introspection;
 use Psr\Log\LogLevel;
 
 /**