]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Logger/Type/StreamLogger.php
Merge branch '2023.03-rc' into stable
[friendica.git] / src / Core / Logger / Type / StreamLogger.php
index 8d4d8b577e4705a64e423bfe6f71808fa2e38877..d56f5b20ef6fd2b8fa001f20d9ab811597f1efea 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
 
 namespace Friendica\Core\Logger\Type;
 
+use Friendica\Core\Config\Capability\IManageConfigValues;
+use Friendica\Core\Hooks\Capabilities\IAmAStrategy;
+use Friendica\Core\Logger\Capabilities\IHaveCallIntrospections;
 use Friendica\Core\Logger\Exception\LoggerArgumentException;
 use Friendica\Core\Logger\Exception\LoggerException;
 use Friendica\Core\Logger\Exception\LogLevelException;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\FileSystem;
-use Friendica\Core\Logger\Util\Introspection;
 use Psr\Log\LogLevel;
 
 /**
  * A Logger instance for logging into a stream (file, stdout, stderr)
  */
-class StreamLogger extends AbstractLogger
+class StreamLogger extends AbstractLogger implements IAmAStrategy
 {
        /**
         * The minimum loglevel at which this logger will be triggered
@@ -80,16 +82,20 @@ class StreamLogger extends AbstractLogger
 
        /**
         * {@inheritdoc}
-        * @param string|resource $stream The stream to write with this logger (either a file or a stream, i.e. stdout)
         * @param string          $level  The minimum loglevel at which this logger will be triggered
         *
         * @throws LoggerArgumentException
         * @throws LogLevelException
         */
-       public function __construct($channel, $stream, Introspection $introspection, FileSystem $fileSystem, string $level = LogLevel::DEBUG)
+       public function __construct(string $channel, IManageConfigValues $config, IHaveCallIntrospections $introspection, FileSystem $fileSystem, string $level = LogLevel::DEBUG)
        {
                $this->fileSystem = $fileSystem;
 
+               $stream = $this->logfile ?? $config->get('system', 'logfile');
+               if ((@file_exists($stream) && !@is_writable($stream)) && !@is_writable(basename($stream))) {
+                       throw new LoggerArgumentException(sprintf('%s is not a valid logfile', $stream));
+               }
+
                parent::__construct($channel, $introspection);
 
                if (is_resource($stream)) {