]> git.mxchange.org Git - friendica.git/blobdiff - src/App.php
Add Monolog
[friendica.git] / src / App.php
index df350542ad2c8c6463e5451acbd9f4a031fa1271..793590bae43205ef14f88e6c25b8d37540ebeb20 100644 (file)
@@ -8,8 +8,10 @@ use Detection\MobileDetect;
 use DOMDocument;
 use DOMXPath;
 use Exception;
+use Friendica\Core\Logger;
 use Friendica\Database\DBA;
 use Friendica\Network\HTTPException\InternalServerErrorException;
+use Monolog;
 
 /**
  *
@@ -106,6 +108,11 @@ class App
         */
        public $mobileDetect;
 
+       /**
+        * @var Monolog\Logger The current logger of this App
+        */
+       private $logger;
+
        /**
         * Register a stylesheet file path to be included in the <head> tag of every page.
         * Inclusion is done in App->initHead().
@@ -147,12 +154,15 @@ class App
         * @brief App constructor.
         *
         * @param string $basePath  Path to the app base folder
+        * @param Monolog\Logger    Logger of this application
         * @param bool   $isBackend Whether it is used for backend or frontend (Default true=backend)
         *
         * @throws Exception if the Basepath is not usable
         */
-       public function __construct($basePath, $isBackend = true)
+       public function __construct($basePath, $logger, $isBackend = true)
        {
+               $this->logger = $logger;
+
                if (!static::isDirectoryUsable($basePath, false)) {
                        throw new Exception('Basepath ' . $basePath . ' isn\'t usable.');
                }
@@ -301,6 +311,21 @@ class App
                return $this->mode;
        }
 
+       /**
+        * Returns the Logger of the Application
+        *
+        * @return Monolog\Logger The Logger
+        * @throws InternalServerErrorException when the logger isn't created
+        */
+       public function getLogger()
+       {
+               if (empty($this->logger)) {
+                       throw new InternalServerErrorException('Logger of the Application is not defined');
+               }
+
+               return $this->logger;
+       }
+
        /**
         * Reloads the whole app instance
         */
@@ -328,6 +353,8 @@ class App
                Core\L10n::init();
 
                $this->process_id = Core\System::processID('log');
+
+               Logger::loadDefaultHandler($this->logger, $this);
        }
 
        /**