]> git.mxchange.org Git - core.git/blobdiff - framework/main/middleware/debug/class_DebugMiddleware.php
Continued:
[core.git] / framework / main / middleware / debug / class_DebugMiddleware.php
index 959c9272e74f3009905c7dd52341a4260e5209cf..53a2ece66208bb4d9bd4b7864d7fff75931fdd74 100644 (file)
@@ -4,7 +4,9 @@ namespace Org\Mxchange\CoreFramework\Middleware\Debug;
 
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 use Org\Mxchange\CoreFramework\Generic\NullPointerException;
+use Org\Mxchange\CoreFramework\Logging\Logger;
 use Org\Mxchange\CoreFramework\Middleware\BaseMiddleware;
 use Org\Mxchange\CoreFramework\Registry\Registerable;
 use Org\Mxchange\CoreFramework\Stream\Output\OutputStreamer;
@@ -37,7 +39,7 @@ use \InvalidArgumentException;
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
-class DebugMiddleware extends BaseMiddleware implements Registerable {
+class DebugMiddleware extends BaseMiddleware implements Registerable, Logger {
        /**
         * An instance of this class
         */
@@ -121,16 +123,17 @@ class DebugMiddleware extends BaseMiddleware implements Registerable {
         * @return      void
         * @throws      NullPointerException    If this->outputInstance is NULL
         */
-       private function output (string $message, bool $stripTags = false) {
+       private function outputMessage (string $logLevel, string $message, bool $stripTags = false) {
                // Get backtrace
-               //* NOISY-DEBUG: */ printf('[%s:%d]: message=%s,stripTags=%d - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $message, intval($stripTags));
+               //* NOISY-DEBUG: */ printf('[%s:%d]: logLevel=%s,message=%s,stripTags=%d - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $logLevel, $message, intval($stripTags));
                $backtrace = debug_backtrace(!DEBUG_BACKTRACE_PROVIDE_OBJECT);
 
                // Is the deprecated debugOutput() or partialStub() invoked before?
                if (isset($backtrace[4]) && $backtrace[3]['function'] == 'partialStub') {
                        // Prepend class::function:line from 2nd element
                        //* NOISY-DEBUG: */ printf('[%s:%d]: partialStub() was invoked ...' . PHP_EOL, __METHOD__, __LINE__);
-                       $message = sprintf('[%s::%s:%d]: %s',
+                       $message = sprintf('[%s] [%s::%s:%d]: %s',
+                               $logLevel,
                                $backtrace[4]['class'],
                                $backtrace[4]['function'],
                                (isset($backtrace[4]['line']) ? $backtrace[4]['line'] : '0'),
@@ -139,7 +142,8 @@ class DebugMiddleware extends BaseMiddleware implements Registerable {
                } elseif (isset($backtrace[3]) && $backtrace[2]['function'] == 'debugOutput') {
                        // Prepend class::function:line from 2nd element
                        //* NOISY-DEBUG: */ printf('[%s:%d]: debugOutput() was invoked ...' . PHP_EOL, __METHOD__, __LINE__);
-                       $message = sprintf('[%s::%s:%d]: DEPRECATED: %s',
+                       $message = sprintf('[%s] [%s::%s:%d]: %s',
+                               $logLevel,
                                $backtrace[3]['class'],
                                $backtrace[3]['function'],
                                (isset($backtrace[3]['line']) ? $backtrace[3]['line'] : '0'),
@@ -148,7 +152,8 @@ class DebugMiddleware extends BaseMiddleware implements Registerable {
                } else {
                        // Prepend class::function:line from 2nd element
                        //* NOISY-DEBUG: */ printf('[%s:%d]: Ordinary invocation ...' . PHP_EOL, __METHOD__, __LINE__);
-                       $message = sprintf('[%s::%s:%d]: %s',
+                       $message = sprintf('[%s] [%s::%s:%d]: %s',
+                               $logLevel,
                                $backtrace[2]['class'],
                                $backtrace[2]['function'],
                                (isset($backtrace[2]['line']) ? $backtrace[2]['line'] : '0'),
@@ -197,8 +202,8 @@ class DebugMiddleware extends BaseMiddleware implements Registerable {
                }
 
                // Use debug output handler
-               //* NOISY-DEBUG: */ printf('[%s:%d]: Invoking this->output(%s,%d) ...' . PHP_EOL, __METHOD__, __LINE__, $message, intval($stripTags));
-               $this->output($message, $stripTags);
+               //* NOISY-DEBUG: */ printf('[%s:%d]: Invoking this->outputMessage(%s,%s,%d) ...' . PHP_EOL, __METHOD__, __LINE__, Logger::LOGGER_LEVEL_TRACE, $message, intval($stripTags));
+               $this->outputMessage(Logger::LOGGER_LEVEL_TRACE, $message, $stripTags);
 
                // Trace message
                //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__);
@@ -229,8 +234,40 @@ class DebugMiddleware extends BaseMiddleware implements Registerable {
                }
 
                // Use debug output handler
-               //* NOISY-DEBUG: */ printf('[%s:%d]: Invoking this->output(%s,%d) ...' . PHP_EOL, __METHOD__, __LINE__, $message, intval($stripTags));
-               $this->output($message, $stripTags);
+               //* NOISY-DEBUG: */ printf('[%s:%d]: Invoking this->outputMessage(%s,%s,%d) ...' . PHP_EOL, __METHOD__, __LINE__, $message, intval($stripTags));
+               $this->outputMessage(Logger::LOGGER_LEVEL_DEBUG, $message, $stripTags);
+
+               // Trace message
+               //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__);
+       }
+
+       /**
+        * Outputs an informational message whether to debug instance (should be set!) or
+        * dies with or ptints the message. Do NEVER EVER rewrite the exit() call to
+        * ApplicationEntryPoint::app_exit(), this would cause an endless loop.
+        *
+        * @param       $message        Message we shall send out...
+        * @param       $doPrint        Whether print or die here (default: print)
+        * @paran       $stripTags      Whether to strip tags (default: false)
+        * @return      void
+        * @throws      InvalidArgumentException        If a parameter has an invalid value
+        * @throws      NullPointerException    If this->outputInstance is NULL
+        * @todo        Remove $doPrint parameter
+        */
+       public function infoMessage (string $message, bool $doPrint = true, bool $stripTags = false) {
+               // Check parameter
+               //* NOISY-DEBUG: */ printf('[%s:%d]: message=%s,doPrint=%d,stripTags=%d - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $message, intval($doPrint), intval($stripTags));
+               if (empty($message)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "message" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+               } elseif (is_null($this->getOutputInstance())) {
+                       // Should not be NULL
+                       throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
+               }
+
+               // Use debug output handler
+               //* NOISY-DEBUG: */ printf('[%s:%d]: Invoking this->outputMessage(%s,%s,%d) ...' . PHP_EOL, __METHOD__, __LINE__, Logger::LOGGER_LEVEL_INFO, $message, intval($stripTags));
+               $this->outputMessage(Logger::LOGGER_LEVEL_INFO, $message, $stripTags);
 
                // Trace message
                //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__);
@@ -261,8 +298,8 @@ class DebugMiddleware extends BaseMiddleware implements Registerable {
                }
 
                // Use debug output handler
-               //* NOISY-DEBUG: */ printf('[%s:%d]: Invoking this->output(%s,%d) ...' . PHP_EOL, __METHOD__, __LINE__, $message, intval($stripTags));
-               $this->output($message, $stripTags);
+               //* NOISY-DEBUG: */ printf('[%s:%d]: Invoking this->outputMessage(%s,%s,%d) ...' . PHP_EOL, __METHOD__, __LINE__, Logger::LOGGER_LEVEL_WARNING, $message, intval($stripTags));
+               $this->outputMessage(Logger::LOGGER_LEVEL_WARNING, $message, $stripTags);
 
                // Trace message
                //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__);
@@ -286,14 +323,15 @@ class DebugMiddleware extends BaseMiddleware implements Registerable {
                }
 
                // Output stub message
-               $this->output($stubMessage);
+               //* NOISY-DEBUG: */ printf('[%s:%d]: Invoking this->outputMessage(%s,%s) ...' . PHP_EOL, __METHOD__, __LINE__, Logger::LOGGER_LEVEL_WARNING, $subMessage);
+               $this->outputMessage(Logger::LOGGER_LEVEL_WARNING, $stubMessage);
 
                // Trace message
                //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__);
        }
 
        /**
-        * Outputs a debug message whether to debug instance (should be set!) or
+        * Outputs a deprecated message whether to debug instance (should be set!) or
         * dies with or ptints the message. Do NEVER EVER rewrite the exit() call to
         * ApplicationEntryPoint::app_exit(), this would cause an endless loop.
         *
@@ -304,7 +342,7 @@ class DebugMiddleware extends BaseMiddleware implements Registerable {
         * @throws      InvalidArgumentException        If a parameter has an invalid value
         * @throws      NullPointerException    If this->outputInstance is NULL
         * @todo        Remove $doPrint parameter
-        * @deprecated  Rewrite to "new" methods above
+        * @todo        When all old method invocations are fixed, renamed this do deprecatedMessage
         */
        public function debugOutput (string $message, bool $doPrint = true, bool $stripTags = false) {
                // Check parameter
@@ -317,8 +355,9 @@ class DebugMiddleware extends BaseMiddleware implements Registerable {
                        throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
                }
 
-               // Invoke new version
-               $this->debugMessage($message, $doPrint, $stripTags);
+               // Invoke Inner method
+               //* NOISY-DEBUG: */ printf('[%s:%d]: Invoking this->outputMessage(%s,%s) ...' . PHP_EOL, __METHOD__, __LINE__, Logger::LOGGER_LEVEL_DEPRECATED, $subMessage);
+               $this->outputMessage(Logger::LOGGER_LEVEL_DEPRECATED, $message, $doPrint, $stripTags);
 
                // Trace message
                //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__);