]> git.mxchange.org Git - friendica.git/blobdiff - src/App/Page.php
Merge pull request #11910 from annando/logging
[friendica.git] / src / App / Page.php
index 14f0101ef07eb6f49d0207ec7620274c917a62c7..63314561191a672b9ed8aced03a99bb3382e62b5 100644 (file)
@@ -30,6 +30,7 @@ use Friendica\Core\Config\Capability\IManageConfigValues;
 use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
 use Friendica\Core\Hook;
 use Friendica\Core\L10n;
+use Friendica\Core\Logger;
 use Friendica\Core\Renderer;
 use Friendica\Core\System;
 use Friendica\Core\Theme;
@@ -78,14 +79,42 @@ class Page implements ArrayAccess
         */
        private $basePath;
 
+       private $timestamp = 0;
+       private $method    = '';
+       private $module    = '';
+       private $command   = '';
+
        /**
         * @param string $basepath The Page basepath
         */
        public function __construct(string $basepath)
        {
+               $this->timestamp = microtime(true);
                $this->basePath = $basepath;
        }
 
+       public function setLogging(string $method, string $module, string $command)
+       {
+               $this->method  = $method;
+               $this->module  = $module;
+               $this->command = $command;
+       }
+
+       public function logRuntime(IManageConfigValues $config, string $origin = '')
+       {
+               $ignore = $config->get('system', 'runtime_ignore');
+               if (in_array($this->module, $ignore) || in_array($this->command, $ignore)) {
+                       return;
+               }
+
+               $signature = !empty($_SERVER['HTTP_SIGNATURE']);
+               $load      = number_format(System::currentLoad(), 2);
+               $runtime   = number_format(microtime(true) - $this->timestamp, 3);
+               if ($runtime > $config->get('system', 'runtime_loglimit')) {
+                       Logger::debug('Runtime', ['method' => $this->method, 'module' => $this->module, 'runtime' => $runtime, 'load' => $load, 'origin' => $origin, 'signature' => $signature, 'request' => $_SERVER['REQUEST_URI'] ?? '']);
+               }
+       }
+
        /**
         * Whether a offset exists
         *
@@ -171,7 +200,7 @@ class Page implements ArrayAccess
         * @param string $media
         * @see Page::initHead()
         */
-       public function registerStylesheet($path, string $media = 'screen')
+       public function registerStylesheet(string $path, string $media = 'screen')
        {
                $path = Network::appendQueryParam($path, ['v' => FRIENDICA_VERSION]);
 
@@ -264,7 +293,7 @@ class Page implements ArrayAccess
         *
         * Taken from http://webcheatsheet.com/php/get_current_page_url.php
         */
-       private function curPageURL()
+       private function curPageURL(): string
        {
                $pageURL = 'http';
                if (!empty($_SERVER["HTTPS"]) && ($_SERVER["HTTPS"] == "on")) {
@@ -421,6 +450,9 @@ class Page implements ArrayAccess
        {
                $moduleName = $args->getModuleName();
 
+               $this->command = $moduleName;
+               $this->method  = $args->getMethod();
+
                /* Create the page content.
                 * Calls all hooks which are including content operations
                 *