3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Core\Logger\Util;
24 use Friendica\Core\Config\Capability\IManageConfigValues;
25 use Friendica\Core\L10n;
26 use Friendica\Core\Logger\Capability\ICheckLoggerSettings;
27 use Friendica\Core\Logger\Exception\LoggerUnusableException;
30 class LoggerSettingsCheck implements ICheckLoggerSettings
32 /** @var IManageConfigValues */
34 /** @var $fileSystem */
35 protected $fileSystem;
39 public function __construct(IManageConfigValues $config, FileSystem $fileSystem, L10n $l10n)
41 $this->config = $config;
42 $this->fileSystem = $fileSystem;
47 public function checkLogfile(): ?string
49 // Check logfile permission
50 if ($this->config->get('system', 'debugging')) {
51 $file = $this->config->get('system', 'logfile');
54 $stream = $this->fileSystem->createStream($file);
56 if (!isset($stream)) {
57 throw new LoggerUnusableException('Stream is null.');
59 } catch (\Throwable $exception) {
60 return $this->l10n->t('The logfile \'%s\' is not usable. No logging possible (error: \'%s\')', $file, $exception->getMessage());
68 public function checkDebugLogfile(): ?string
70 // Check logfile permission
71 if ($this->config->get('system', 'debugging')) {
72 $file = $this->config->get('system', 'dlogfile');
79 $stream = $this->fileSystem->createStream($file);
81 if (!isset($stream)) {
82 throw new LoggerUnusableException('Stream is null.');
84 } catch (\Throwable $exception) {
85 return $this->l10n->t('The debug logfile \'%s\' is not usable. No logging possible (error: \'%s\')', $file, $exception->getMessage());