]> git.mxchange.org Git - friendica.git/commitdiff
Refactor Loglevels
authorPhilipp Holzer <admin@philipp.info>
Thu, 3 Jan 2019 08:00:49 +0000 (09:00 +0100)
committerHypolite Petovan <hypolite@mrpetovan.com>
Mon, 21 Jan 2019 15:00:46 +0000 (10:00 -0500)
include/api.php
src/App.php
src/Core/Logger.php

index 1b0b35a68e4594aaf6c19dbf9d6da36c14210d50..d762507cf81f02f98fbd9c3c74556bf3fdab719c 100644 (file)
@@ -325,7 +325,7 @@ function api_call(App $a)
 
                                        /// @TODO round() really everywhere?
                                        Logger::debug(
-                                               'API {action} performance',
+                                               API_LOG_PREFIX . 'performance',
                                                [
                                                        'module' => 'api',
                                                        'action' => 'call',
@@ -380,7 +380,7 @@ function api_call(App $a)
                                                                $o .= $func . ": " . $time . "\n";
                                                        }
                                                }
-                                               Logger::debug($o, ['module' => 'api', 'action' => 'call']);
+                                               Logger::debug(API_LOG_PREFIX . $o, ['module' => 'api', 'action' => 'call']);
                                        }
                                }
 
@@ -4842,7 +4842,6 @@ function api_friendica_remoteauth()
                'sec' => $sec, 'expire' => time() + 45];
        DBA::insert('profile_check', $fields);
 
-       $a = get_app();
        Logger::info(API_LOG_PREFIX . 'for contact {contact}', ['module' => 'api', 'action' => 'friendica_remoteauth', 'contact' => $contact['name'], 'hey' => $sec]);
        $dest = ($url ? '&destination_url=' . $url : '');
 
index cfe254581a6d8bd0ece9f50684ef8a68f7fb147a..f5dba13dc08e61a79d699c75d986faea79277a2a 100644 (file)
@@ -159,7 +159,7 @@ class App
         *
         * @throws Exception if the Basepath is not usable
         */
-       public function __construct($basePath, $logger, $isBackend = true)
+       public function __construct($basePath, LoggerInterface $logger, $isBackend = true)
        {
                $this->logger = $logger;
 
index fe39d3feb2c43c6ff548e46b010a8897c07c7f87..c6b81e0cc993eea1ef1060f75a3f229a291f7212 100644 (file)
@@ -16,35 +16,29 @@ use Psr\Log\LogLevel;
 class Logger extends BaseObject
 {
        /**
-        * @deprecated 2019.03 use Logger::error() instead
         * @see Logger::error()
         */
-       const WARNING = 0;
+       const WARNING = LogLevel::ERROR;
        /**
-        * @deprecated 2019.03 use Logger::warning() instead
         * @see Logger::warning()
         */
-       const INFO = 1;
+       const INFO = LogLevel::WARNING;
        /**
-        * @deprecated 2019.03 use Logger::notice() instead
         * @see Logger::notice()
         */
-       const TRACE = 2;
+       const TRACE = LogLevel::NOTICE;
        /**
-        * @deprecated 2019.03 use Logger::info() instead
         * @see Logger::info()
         */
-       const DEBUG = 3;
+       const DEBUG = LogLevel::INFO;
        /**
-        * @deprecated 2019.03 use Logger::debug() instead
         * @see Logger::debug()
         */
-       const DATA = 4;
+       const DATA = LogLevel::DEBUG;
        /**
-        * @deprecated 2019.03 use Logger::debug() instead
         * @see Logger::debug()
         */
-       const ALL = 5;
+       const ALL = LogLevel::DEBUG;
 
        /**
         * @var array the legacy loglevels
@@ -285,34 +279,6 @@ class Logger extends BaseObject
                self::getApp()->saveTimestamp($stamp1, 'file');
        }
 
-       /**
-        * Mapping a legacy level to the PSR-3 compliant levels
-        * @see https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md#5-psrlogloglevel
-        *
-        * @param int $level the level to be mapped
-        *
-        * @return string the PSR-3 compliant level
-        */
-       private static function mapPSR3Level($level)
-       {
-               switch ($level) {
-                       case self::WARNING:
-                               return LogLevel::ERROR;
-                       case self::INFO:
-                               return LogLevel::WARNING;
-                       case self::TRACE:
-                               return LogLevel::NOTICE;
-                       case self::DEBUG:
-                               return LogLevel::INFO;
-                       case self::DATA:
-                               return LogLevel::DEBUG;
-                       case self::ALL:
-                               return LogLevel::DEBUG;
-                       default:
-                               return LogLevel::CRITICAL;
-               }
-       }
-
     /**
      * @brief Logs the given message at the given log level
      *
@@ -321,16 +287,14 @@ class Logger extends BaseObject
         *
         * @deprecated since 2019.03 Use Logger::debug() Logger::info() , ... instead
      */
-    public static function log($msg, $level = self::INFO)
+    public static function log($msg, $level = LogLevel::NOTICE)
     {
                if (!isset(self::$logger)) {
                        return;
                }
 
-               $loglevel = self::mapPSR3Level($level);
-
         $stamp1 = microtime(true);
-               self::$logger->log($loglevel, $msg);
+               self::$logger->log($level, $msg);
         self::getApp()->saveTimestamp($stamp1, "file");
     }