]> git.mxchange.org Git - friendica.git/commitdiff
Moving Profiling to class
authorPhilipp Holzer <admin@philipp.info>
Thu, 28 Feb 2019 08:41:31 +0000 (09:41 +0100)
committerHypolite Petovan <hypolite@mrpetovan.com>
Sat, 23 Mar 2019 03:07:39 +0000 (23:07 -0400)
src/Core/Logger.php
src/Factory/DependencyFactory.php
src/Factory/LoggerFactory.php
src/Util/Logger/AbstractFriendicaLogger.php [new file with mode: 0644]
src/Util/Logger/StreamLogger.php
src/Util/Logger/SyslogLogger.php
tests/include/ApiTest.php
tests/src/Database/DBATest.php
tests/src/Database/DBStructureTest.php

index 3cb22e1e478aeef78dc2e2467af3fe35523c4771..fc2dde1dfe703f3de75e6044cc7fccc8b699e7bd 100644 (file)
@@ -4,14 +4,13 @@
  */
 namespace Friendica\Core;
 
-use Friendica\BaseObject;
 use Psr\Log\LoggerInterface;
 use Psr\Log\LogLevel;
 
 /**
  * @brief Logger functions
  */
-class Logger extends BaseObject
+class Logger
 {
        /**
         * @see Logger::error()
@@ -96,13 +95,7 @@ class Logger extends BaseObject
         */
        public static function emergency($message, $context = [])
        {
-               if (!isset(self::$logger)) {
-                       return;
-               }
-
-               $stamp1 = microtime(true);
                self::$logger->emergency($message, $context);
-               self::getApp()->GetProfiler()->saveTimestamp($stamp1, 'file', System::callstack());
        }
 
        /**
@@ -120,13 +113,7 @@ class Logger extends BaseObject
         */
        public static function alert($message, $context = [])
        {
-               if (!isset(self::$logger)) {
-                       return;
-               }
-
-               $stamp1 = microtime(true);
                self::$logger->alert($message, $context);
-               self::getApp()->getProfiler()->saveTimestamp($stamp1, 'file', System::callstack());
        }
 
        /**
@@ -143,13 +130,7 @@ class Logger extends BaseObject
         */
        public static function critical($message, $context = [])
        {
-               if (!isset(self::$logger)) {
-                       return;
-               }
-
-               $stamp1 = microtime(true);
                self::$logger->critical($message, $context);
-               self::getApp()->getProfiler()->saveTimestamp($stamp1, 'file', System::callstack());
        }
 
        /**
@@ -165,14 +146,7 @@ class Logger extends BaseObject
         */
        public static function error($message, $context = [])
        {
-               if (!isset(self::$logger)) {
-                       echo "not set!?\n";
-                       return;
-               }
-
-               $stamp1 = microtime(true);
                self::$logger->error($message, $context);
-               self::getApp()->getProfiler()->saveTimestamp($stamp1, 'file', System::callstack());
        }
 
        /**
@@ -190,13 +164,7 @@ class Logger extends BaseObject
         */
        public static function warning($message, $context = [])
        {
-               if (!isset(self::$logger)) {
-                       return;
-               }
-
-               $stamp1 = microtime(true);
                self::$logger->warning($message, $context);
-               self::getApp()->getProfiler()->saveTimestamp($stamp1, 'file', System::callstack());
        }
 
        /**
@@ -211,13 +179,7 @@ class Logger extends BaseObject
         */
        public static function notice($message, $context = [])
        {
-               if (!isset(self::$logger)) {
-                       return;
-               }
-
-               $stamp1 = microtime(true);
                self::$logger->notice($message, $context);
-               self::getApp()->getProfiler()->saveTimestamp($stamp1, 'file', System::callstack());
        }
 
        /**
@@ -234,13 +196,7 @@ class Logger extends BaseObject
         */
        public static function info($message, $context = [])
        {
-               if (!isset(self::$logger)) {
-                       return;
-               }
-
-               $stamp1 = microtime(true);
                self::$logger->info($message, $context);
-               self::getApp()->getProfiler()->saveTimestamp($stamp1, 'file', System::callstack());
        }
 
        /**
@@ -255,13 +211,7 @@ class Logger extends BaseObject
         */
        public static function debug($message, $context = [])
        {
-               if (!isset(self::$logger)) {
-                       return;
-               }
-
-               $stamp1 = microtime(true);
                self::$logger->debug($message, $context);
-               self::getApp()->getProfiler()->saveTimestamp($stamp1, 'file', System::callstack());
        }
 
            /**
@@ -275,13 +225,7 @@ class Logger extends BaseObject
         */
        public static function log($msg, $level = LogLevel::INFO)
        {
-               if (!isset(self::$logger)) {
-                       return;
-               }
-
-               $stamp1 = microtime(true);
                self::$logger->log($level, $msg);
-               self::getApp()->getProfiler()->saveTimestamp($stamp1, "file", System::callstack());
        }
 
        /**
@@ -296,12 +240,10 @@ class Logger extends BaseObject
         */
        public static function devLog($msg, $level = LogLevel::DEBUG)
        {
-               if (!isset(self::$logger)) {
+               if (!isset(self::$devLogger)) {
                        return;
                }
 
-               $stamp1 = microtime(true);
                self::$devLogger->log($level, $msg);
-               self::getApp()->getProfiler()->saveTimestamp($stamp1, "file", System::callstack());
        }
 }
index 9d84e324ab5370a32bb7b7692d109b9432c72ae1..67384452e92f93b028a38f46f12a9671ea2fbab9 100644 (file)
@@ -30,7 +30,7 @@ class DependencyFactory
                $config = Factory\ConfigFactory::createConfig($configCache);
                // needed to call PConfig::init()
                Factory\ConfigFactory::createPConfig($configCache);
-               $logger = Factory\LoggerFactory::create($channel, $config);
+               $logger = Factory\LoggerFactory::create($channel, $config, $profiler);
                Factory\LoggerFactory::createDev($channel, $config);
 
                return new App($basePath, $config, $logger, $profiler, $isBackend);
index f940d9d84c9b189db6e6a96311a1c04453e38e53..ebcb3bd2b0bfe5e334232251d6e0e58c10379190 100644 (file)
@@ -38,13 +38,14 @@ class LoggerFactory
         *
         * @param string        $channel The channel of the logger instance
         * @param Configuration $config  The config
+        * @param Profiler      $profiler The profiler of the app
         *
         * @return LoggerInterface The PSR-3 compliant logger instance
         *
         * @throws \Exception
         * @throws InternalServerErrorException
         */
-       public static function create($channel, Configuration $config)
+       public static function create($channel, Configuration $config, Profiler $profiler)
        {
                if (empty($config->get('system', 'debugging', false))) {
                        $logger = new VoidLogger();
@@ -58,7 +59,7 @@ class LoggerFactory
                        case 'syslog':
                                $level = $config->get('system', 'loglevel');
 
-                               $logger = new SyslogLogger($channel, $introspection, $level);
+                               $logger = new SyslogLogger($channel, $introspection, $profiler, $level);
                                break;
                        case 'monolog':
                        default:
diff --git a/src/Util/Logger/AbstractFriendicaLogger.php b/src/Util/Logger/AbstractFriendicaLogger.php
new file mode 100644 (file)
index 0000000..3f851f4
--- /dev/null
@@ -0,0 +1,185 @@
+<?php
+
+namespace Friendica\Util\Logger;
+
+use Friendica\Core\System;
+use Friendica\Util\Introspection;
+use Friendica\Util\Profiler;
+use Friendica\Util\Strings;
+use Psr\Log\LoggerInterface;
+use Psr\Log\LogLevel;
+
+/**
+ * This class contains all necessary dependencies and calls for Friendica
+ * Every new Logger should extend this class and define, how addEntry() works
+ *
+ * Contains:
+ * - Introspection
+ * - Automatic Friendica profiling
+ */
+abstract class AbstractFriendicaLogger implements LoggerInterface
+{
+       /**
+        * The output channel of this logger
+        * @var string
+        */
+       protected $channel;
+
+       /**
+        * The Introspection for the current call
+        * @var Introspection
+        */
+       protected $introspection;
+
+       /**
+        * The Profiler for the current call
+        * @var Profiler
+        */
+       protected $profiler;
+
+       /**
+        * The UID of the current call
+        * @var string
+        */
+       protected $logUid;
+
+       /**
+        * Adds a new entry to the log
+        *
+        * @param int    $level
+        * @param string $message
+        * @param array  $context
+        *
+        * @return void
+        */
+       abstract protected function addEntry($level, $message, $context = []);
+
+       /**
+        * @param string        $channel       The output channel
+        * @param Introspection $introspection The introspection of the current call
+        * @param Profiler      $profiler      The profiler of the current call
+        *
+        * @throws \Exception
+        */
+       public function __construct($channel, Introspection $introspection, Profiler $profiler)
+       {
+               $this->channel       = $channel;
+               $this->introspection = $introspection;
+               $this->profiler      = $profiler;
+               $this->logUid        = Strings::getRandomHex(6);
+       }
+
+       /**
+        * Simple interpolation of PSR-3 compliant replacements ( variables between '{' and '}' )
+        * @see https://www.php-fig.org/psr/psr-3/#12-message
+        *
+        * @param string $message
+        * @param array  $context
+        *
+        * @return string the interpolated message
+        */
+       protected function psrInterpolate($message, array $context = array())
+       {
+               $replace = [];
+               foreach ($context as $key => $value) {
+                       // check that the value can be casted to string
+                       if (!is_array($value) && (!is_object($value) || method_exists($value, '__toString'))) {
+                               $replace['{' . $key . '}'] = $value;
+                       } elseif (is_array($value)) {
+                               $replace['{' . $key . '}'] = @json_encode($value);
+                       }
+               }
+
+               return strtr($message, $replace);
+       }
+
+       /**
+        * {@inheritdoc}
+        */
+       public function emergency($message, array $context = array())
+       {
+               $stamp1 = microtime(true);
+               $this->addEntry(LogLevel::EMERGENCY, $message, $context);
+               $this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
+       }
+
+       /**
+        * {@inheritdoc}
+        */
+       public function alert($message, array $context = array())
+       {
+               $stamp1 = microtime(true);
+               $this->addEntry(LogLevel::ALERT, $message, $context);
+               $this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
+       }
+
+       /**
+        * {@inheritdoc}
+        */
+       public function critical($message, array $context = array())
+       {
+               $stamp1 = microtime(true);
+               $this->addEntry(LogLevel::CRITICAL, $message, $context);
+               $this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
+       }
+
+       /**
+        * {@inheritdoc}
+        */
+       public function error($message, array $context = array())
+       {
+               $stamp1 = microtime(true);
+               $this->addEntry(LogLevel::ERROR, $message, $context);
+               $this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
+       }
+
+       /**
+        * {@inheritdoc}
+        */
+       public function warning($message, array $context = array())
+       {
+               $stamp1 = microtime(true);
+               $this->addEntry(LogLevel::WARNING, $message, $context);
+               $this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
+       }
+
+       /**
+        * {@inheritdoc}
+        */
+       public function notice($message, array $context = array())
+       {
+               $stamp1 = microtime(true);
+               $this->addEntry(LogLevel::NOTICE, $message, $context);
+               $this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
+       }
+
+       /**
+        * {@inheritdoc}
+        */
+       public function info($message, array $context = array())
+       {
+               $stamp1 = microtime(true);
+               $this->addEntry(LogLevel::INFO, $message, $context);
+               $this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
+       }
+
+       /**
+        * {@inheritdoc}
+        */
+       public function debug($message, array $context = array())
+       {
+               $stamp1 = microtime(true);
+               $this->addEntry(LogLevel::DEBUG, $message, $context);
+               $this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
+       }
+
+       /**
+        * {@inheritdoc}
+        */
+       public function log($level, $message, array $context = array())
+       {
+               $stamp1 = microtime(true);
+               $this->addEntry($level, $message, $context);
+               $this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
+       }
+}
index 7b9bbb3c1bdc237e7133d2437bef939b46d6e7e2..4ccbc8283b8760056114e2d64db22d2565da6f8e 100644 (file)
 
 namespace Friendica\Util\Logger;
 
-use Friendica\Network\HTTPException\InternalServerErrorException;
 use Friendica\Util\Introspection;
-use Friendica\Util\Strings;
-use Psr\Log\InvalidArgumentException;
-use Psr\Log\LoggerInterface;
-use Psr\Log\LogLevel;
+use Friendica\Util\Profiler;
 
 /**
  * A Logger instance for logging into a stream
- * @see http://php.net/manual/en/function.syslog.php
  */
-class StreamLogger implements LoggerInterface
+class StreamLogger extends AbstractFriendicaLogger
 {
-       const IDENT = 'Friendica';
-
-       /**
-        * Translates LogLevel log levels to syslog log priorities.
-        * @var array
-        */
-       private $logLevels = [
-               LogLevel::DEBUG     => LOG_DEBUG,
-               LogLevel::INFO      => LOG_INFO,
-               LogLevel::NOTICE    => LOG_NOTICE,
-               LogLevel::WARNING   => LOG_WARNING,
-               LogLevel::ERROR     => LOG_ERR,
-               LogLevel::CRITICAL  => LOG_CRIT,
-               LogLevel::ALERT     => LOG_ALERT,
-               LogLevel::EMERGENCY => LOG_EMERG,
-       ];
-
-       /**
-        * Translates log priorities to string outputs
-        * @var array
-        */
-       private $logToString = [
-               LOG_DEBUG   => 'DEBUG',
-               LOG_INFO    => 'INFO',
-               LOG_NOTICE  => 'NOTICE',
-               LOG_WARNING => 'WARNING',
-               LOG_ERR     => 'ERROR',
-               LOG_CRIT    => 'CRITICAL',
-               LOG_ALERT   => 'ALERT',
-               LOG_EMERG   => 'EMERGENCY'
-       ];
-
-       /**
-        * The channel of the current process (added to each message)
-        * @var string
-        */
-       private $channel;
-
-       /**
-        * Indicates what logging options will be used when generating a log message
-        * @see http://php.net/manual/en/function.openlog.php#refsect1-function.openlog-parameters
-        *
-        * @var int
-        */
-       private $logOpts;
-
-       /**
-        * Used to specify what type of program is logging the message
-        * @see http://php.net/manual/en/function.openlog.php#refsect1-function.openlog-parameters
-        *
-        * @var int
-        */
-       private $logFacility;
-
-       /**
-        * The minimum loglevel at which this logger will be triggered
-        * @var int
-        */
-       private $logLevel;
-
-       /**
-        * The Introspection for the current call
-        * @var Introspection
-        */
-       private $introspection;
-
-       /**
-        * The UID of the current call
-        * @var string
-        */
-       private $logUid;
-
-       /**
-        * @param string        $channel       The output channel
-        * @param Introspection $introspection The introspection of the current call
-        * @param string        $level         The minimum loglevel at which this logger will be triggered
-        * @param int           $logOpts       Indicates what logging options will be used when generating a log message
-        * @param int           $logFacility   Used to specify what type of program is logging the message
-        *
-        * @throws \Exception
-        */
-       public function __construct($channel, Introspection $introspection, $level = LogLevel::NOTICE, $logOpts = LOG_PID, $logFacility = LOG_USER)
-       {
-               $this->logUid = Strings::getRandomHex(6);
-               $this->channel = $channel;
-               $this->logOpts = $logOpts;
-               $this->logFacility = $logFacility;
-               $this->logLevel = $this->mapLevelToPriority($level);
-               $this->introspection = $introspection;
-       }
-
-       /**
-        * Maps the LogLevel (@see LogLevel ) to a SysLog priority (@see http://php.net/manual/en/function.syslog.php#refsect1-function.syslog-parameters )
-        *
-        * @param string $level A LogLevel
-        *
-        * @return int The SysLog priority
-        *
-        * @throws \Psr\Log\InvalidArgumentException If the loglevel isn't valid
-        */
-       public function mapLevelToPriority($level)
-       {
-               if (!array_key_exists($level, $this->logLevels)) {
-                       throw new InvalidArgumentException('LogLevel \'' . $level . '\' isn\'t valid.');
-               }
-
-               return $this->logLevels[$level];
-       }
-
-       /**
-        * Writes a message to the syslog
-        * @see http://php.net/manual/en/function.syslog.php#refsect1-function.syslog-parameters
-        *
-        * @param int    $priority The Priority
-        * @param string $message  The message of the log
-        *
-        * @throws InternalServerErrorException if syslog cannot be used
-        */
-       private function write($priority, $message)
-       {
-               if (!openlog(self::IDENT, $this->logOpts, $this->logFacility)) {
-                       throw new InternalServerErrorException('Can\'t open syslog for ident "' . $this->channel . '" and facility "' . $this->logFacility . '""');
-               }
-
-               syslog($priority, $message);
-       }
-
-       /**
-        * Closes the Syslog
-        */
-       public function close()
-       {
-               closelog();
-       }
-
-       /**
-        * Formats a log record for the syslog output
-        *
-        * @param int    $level   The loglevel/priority
-        * @param string $message The message
-        * @param array  $context The context of this call
-        *
-        * @return string the formatted syslog output
-        */
-       private function formatLog($level, $message, $context = [])
+       public function __construct($channel, Introspection $introspection, Profiler $profiler)
        {
-               $record = $this->introspection->getRecord();
-               $record = array_merge($record, ['uid' => $this->logUid]);
-               $logMessage = '';
-
-               $logMessage .= $this->channel . ' ';
-               $logMessage .= '[' . $this->logToString[$level] . ']: ';
-               $logMessage .= $this->psrInterpolate($message, $context) . ' ';
-               $logMessage .= @json_encode($context) . ' - ';
-               $logMessage .= @json_encode($record);
-
-               return $logMessage;
+               parent::__construct($channel, $introspection, $profiler);
        }
 
        /**
-        * Simple interpolation of PSR-3 compliant replacements ( variables between '{' and '}' )
-        * @see https://www.php-fig.org/psr/psr-3/#12-message
+        * Adds a new entry to the log
         *
+        * @param int $level
         * @param string $message
-        * @param array  $context
+        * @param array $context
         *
-        * @return string the interpolated message
-        */
-       private function psrInterpolate($message, array $context = array())
-       {
-               $replace = [];
-               foreach ($context as $key => $value) {
-                       // check that the value can be casted to string
-                       if (!is_array($value) && (!is_object($value) || method_exists($value, '__toString'))) {
-                               $replace['{' . $key . '}'] = $value;
-                       } elseif (is_array($value)) {
-                               $replace['{' . $key . '}'] = @json_encode($value);
-                       }
-               }
-
-               return strtr($message, $replace);
-       }
-
-       /**
-        * Adds a new entry to the syslog
-        *
-        * @param int    $level
-        * @param string $message
-        * @param array  $context
-        *
-        * @throws InternalServerErrorException if the syslog isn't available
-        */
-       private function addEntry($level, $message, $context = [])
-       {
-               if ($level >= $this->logLevel) {
-                       return;
-               }
-
-               $formattedLog = $this->formatLog($level, $message, $context);
-               $this->write($level, $formattedLog);
-       }
-
-       /**
-        * {@inheritdoc}
-        * @throws InternalServerErrorException if the syslog isn't available
-        */
-       public function emergency($message, array $context = array())
-       {
-               $this->addEntry(LOG_EMERG, $message, $context);
-       }
-
-       /**
-        * {@inheritdoc}
-        * @throws InternalServerErrorException if the syslog isn't available
-        */
-       public function alert($message, array $context = array())
-       {
-               $this->addEntry(LOG_ALERT, $message, $context);
-       }
-
-       /**
-        * {@inheritdoc}
-        * @throws InternalServerErrorException if the syslog isn't available
-        */
-       public function critical($message, array $context = array())
-       {
-               $this->addEntry(LOG_CRIT, $message, $context);
-       }
-
-       /**
-        * {@inheritdoc}
-        * @throws InternalServerErrorException if the syslog isn't available
-        */
-       public function error($message, array $context = array())
-       {
-               $this->addEntry(LOG_ERR, $message, $context);
-       }
-
-       /**
-        * {@inheritdoc}
-        * @throws InternalServerErrorException if the syslog isn't available
-        */
-       public function warning($message, array $context = array())
-       {
-               $this->addEntry(LOG_WARNING, $message, $context);
-       }
-
-       /**
-        * {@inheritdoc}
-        * @throws InternalServerErrorException if the syslog isn't available
-        */
-       public function notice($message, array $context = array())
-       {
-               $this->addEntry(LOG_NOTICE, $message, $context);
-       }
-
-       /**
-        * {@inheritdoc}
-        * @throws InternalServerErrorException if the syslog isn't available
-        */
-       public function info($message, array $context = array())
-       {
-               $this->addEntry(LOG_INFO, $message, $context);
-       }
-
-       /**
-        * {@inheritdoc}
-        * @throws InternalServerErrorException if the syslog isn't available
-        */
-       public function debug($message, array $context = array())
-       {
-               $this->addEntry(LOG_DEBUG, $message, $context);
-       }
-
-       /**
-        * {@inheritdoc}
-        * @throws InternalServerErrorException if the syslog isn't available
+        * @return void
         */
-       public function log($level, $message, array $context = array())
+       protected function addEntry($level, $message, $context = [])
        {
-               $logLevel = $this->mapLevelToPriority($level);
-               $this->addEntry($logLevel, $message, $context);
+               // TODO: Implement addEntry() method.
        }
 }
index 5cb1f8c9e69b13a4eca3016d69099deca7f54f09..25d8f2f5e2e7e112f1af9919f9d6d8571823904d 100644 (file)
@@ -4,16 +4,15 @@ namespace Friendica\Util\Logger;
 
 use Friendica\Network\HTTPException\InternalServerErrorException;
 use Friendica\Util\Introspection;
-use Friendica\Util\Strings;
+use Friendica\Util\Profiler;
 use Psr\Log\InvalidArgumentException;
-use Psr\Log\LoggerInterface;
 use Psr\Log\LogLevel;
 
 /**
  * A Logger instance for syslogging (fast, but simple)
  * @see http://php.net/manual/en/function.syslog.php
  */
-class SyslogLogger implements LoggerInterface
+class SyslogLogger extends AbstractFriendicaLogger
 {
        const IDENT = 'Friendica';
 
@@ -47,12 +46,6 @@ class SyslogLogger implements LoggerInterface
                LOG_EMERG   => 'EMERGENCY'
        ];
 
-       /**
-        * The channel of the current process (added to each message)
-        * @var string
-        */
-       private $channel;
-
        /**
         * Indicates what logging options will be used when generating a log message
         * @see http://php.net/manual/en/function.openlog.php#refsect1-function.openlog-parameters
@@ -76,34 +69,20 @@ class SyslogLogger implements LoggerInterface
        private $logLevel;
 
        /**
-        * The Introspection for the current call
-        * @var Introspection
-        */
-       private $introspection;
-
-       /**
-        * The UID of the current call
-        * @var string
-        */
-       private $logUid;
-
-       /**
-        * @param string        $channel       The output channel
-        * @param Introspection $introspection The introspection of the current call
+        * {@inheritdoc}
         * @param string        $level         The minimum loglevel at which this logger will be triggered
         * @param int           $logOpts       Indicates what logging options will be used when generating a log message
         * @param int           $logFacility   Used to specify what type of program is logging the message
         *
         * @throws \Exception
         */
-       public function __construct($channel, Introspection $introspection, $level = LogLevel::NOTICE, $logOpts = LOG_PID, $logFacility = LOG_USER)
+       public function __construct($channel, Introspection $introspection, Profiler $profiler, $level = LogLevel::NOTICE, $logOpts = LOG_PID, $logFacility = LOG_USER)
        {
-               $this->logUid = Strings::getRandomHex(6);
-               $this->channel = $channel;
+               parent::__construct($channel, $introspection, $profiler);
                $this->logOpts = $logOpts;
                $this->logFacility = $logFacility;
                $this->logLevel = $this->mapLevelToPriority($level);
-               $this->introspection = $introspection;
+               $this->introspection->addClasses(array(self::class));
        }
 
        /**
@@ -174,30 +153,6 @@ class SyslogLogger implements LoggerInterface
                return $logMessage;
        }
 
-       /**
-        * Simple interpolation of PSR-3 compliant replacements ( variables between '{' and '}' )
-        * @see https://www.php-fig.org/psr/psr-3/#12-message
-        *
-        * @param string $message
-        * @param array  $context
-        *
-        * @return string the interpolated message
-        */
-       private function psrInterpolate($message, array $context = array())
-       {
-               $replace = [];
-               foreach ($context as $key => $value) {
-                       // check that the value can be casted to string
-                       if (!is_array($value) && (!is_object($value) || method_exists($value, '__toString'))) {
-                               $replace['{' . $key . '}'] = $value;
-                       } elseif (is_array($value)) {
-                               $replace['{' . $key . '}'] = @json_encode($value);
-                       }
-               }
-
-               return strtr($message, $replace);
-       }
-
        /**
         * Adds a new entry to the syslog
         *
@@ -207,95 +162,15 @@ class SyslogLogger implements LoggerInterface
         *
         * @throws InternalServerErrorException if the syslog isn't available
         */
-       private function addEntry($level, $message, $context = [])
+       protected function addEntry($level, $message, $context = [])
        {
-               if ($level >= $this->logLevel) {
+               $logLevel = $this->mapLevelToPriority($level);
+
+               if ($logLevel >= $this->logLevel) {
                        return;
                }
 
                $formattedLog = $this->formatLog($level, $message, $context);
                $this->write($level, $formattedLog);
        }
-
-       /**
-        * {@inheritdoc}
-        * @throws InternalServerErrorException if the syslog isn't available
-        */
-       public function emergency($message, array $context = array())
-       {
-               $this->addEntry(LOG_EMERG, $message, $context);
-       }
-
-       /**
-        * {@inheritdoc}
-        * @throws InternalServerErrorException if the syslog isn't available
-        */
-       public function alert($message, array $context = array())
-       {
-               $this->addEntry(LOG_ALERT, $message, $context);
-       }
-
-       /**
-        * {@inheritdoc}
-        * @throws InternalServerErrorException if the syslog isn't available
-        */
-       public function critical($message, array $context = array())
-       {
-               $this->addEntry(LOG_CRIT, $message, $context);
-       }
-
-       /**
-        * {@inheritdoc}
-        * @throws InternalServerErrorException if the syslog isn't available
-        */
-       public function error($message, array $context = array())
-       {
-               $this->addEntry(LOG_ERR, $message, $context);
-       }
-
-       /**
-        * {@inheritdoc}
-        * @throws InternalServerErrorException if the syslog isn't available
-        */
-       public function warning($message, array $context = array())
-       {
-               $this->addEntry(LOG_WARNING, $message, $context);
-       }
-
-       /**
-        * {@inheritdoc}
-        * @throws InternalServerErrorException if the syslog isn't available
-        */
-       public function notice($message, array $context = array())
-       {
-               $this->addEntry(LOG_NOTICE, $message, $context);
-       }
-
-       /**
-        * {@inheritdoc}
-        * @throws InternalServerErrorException if the syslog isn't available
-        */
-       public function info($message, array $context = array())
-       {
-               $this->addEntry(LOG_INFO, $message, $context);
-       }
-
-       /**
-        * {@inheritdoc}
-        * @throws InternalServerErrorException if the syslog isn't available
-        */
-       public function debug($message, array $context = array())
-       {
-               $this->addEntry(LOG_DEBUG, $message, $context);
-       }
-
-       /**
-        * {@inheritdoc}
-        * @throws InternalServerErrorException if the syslog isn't available
-        */
-       public function log($level, $message, array $context = array())
-       {
-               $logLevel = $this->mapLevelToPriority($level);
-               $this->addEntry($logLevel, $message, $context);
-       }
 }
index 2f8becc18cb8195b8beaf10808014e46b0c636d0..394e822201dfd679fe1f88d8c90f108ab44cf887 100644 (file)
@@ -43,7 +43,7 @@ class ApiTest extends DatabaseTest
                Factory\DBFactory::init($basePath, $configCache, $profiler, $_SERVER);
                $config = Factory\ConfigFactory::createConfig($configCache);
                Factory\ConfigFactory::createPConfig($configCache);
-               $logger = Factory\LoggerFactory::create('test', $config);
+               $logger = Factory\LoggerFactory::create('test', $config, $profiler);
                $this->app = new App($basePath, $config, $logger, $profiler, false);
 
                parent::setUp();
index 511821da57d06462d5a551dfa01e488296c458f0..1408fc37bdd20d8dd32af1c9c3ff3b09e1e15f10 100644 (file)
@@ -20,7 +20,7 @@ class DBATest extends DatabaseTest
                Factory\DBFactory::init($basePath, $configCache, $profiler, $_SERVER);
                $config = Factory\ConfigFactory::createConfig($configCache);
                Factory\ConfigFactory::createPConfig($configCache);
-               $logger = Factory\LoggerFactory::create('test', $config);
+               $logger = Factory\LoggerFactory::create('test', $config, $profiler);
                $this->app = new App($basePath, $config, $logger, $profiler, false);
 
                parent::setUp();
index 7b1ff2a31f566dacfc48adae58f936e483e448e4..0efecac234f5e0773d5b77659962df125b1ca32d 100644 (file)
@@ -20,7 +20,7 @@ class DBStructureTest extends DatabaseTest
                Factory\DBFactory::init($basePath, $configCache, $profiler, $_SERVER);
                $config = Factory\ConfigFactory::createConfig($configCache);
                Factory\ConfigFactory::createPConfig($configCache);
-               $logger = Factory\LoggerFactory::create('test', $config);
+               $logger = Factory\LoggerFactory::create('test', $config, $profiler);
                $this->app = new App($basePath, $config, $logger, $profiler, false);
 
                parent::setUp();