]> git.mxchange.org Git - friendica.git/blob - src/Core/Logger/Util/LoggerSettingsCheck.php
Use the owner, not the author
[friendica.git] / src / Core / Logger / Util / LoggerSettingsCheck.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2023, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
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.
11  *
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.
16  *
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/>.
19  *
20  */
21
22 namespace Friendica\Core\Logger\Util;
23
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;
28
29 /** {@inheritDoc} */
30 class LoggerSettingsCheck implements ICheckLoggerSettings
31 {
32         /** @var IManageConfigValues */
33         protected $config;
34         /** @var $fileSystem */
35         protected $fileSystem;
36         /** @var L10n */
37         protected $l10n;
38
39         public function __construct(IManageConfigValues $config, FileSystem $fileSystem, L10n $l10n)
40         {
41                 $this->config     = $config;
42                 $this->fileSystem = $fileSystem;
43                 $this->l10n       = $l10n;
44         }
45
46         /** {@inheritDoc} */
47         public function checkLogfile(): ?string
48         {
49                 // Check logfile permission
50                 if ($this->config->get('system', 'debugging')) {
51                         $file = $this->config->get('system', 'logfile');
52
53                         try {
54                                 $stream = $this->fileSystem->createStream($file);
55
56                                 if (!isset($stream)) {
57                                         throw new LoggerUnusableException('Stream is null.');
58                                 }
59                         } catch (\Throwable $exception) {
60                                 return $this->l10n->t('The logfile \'%s\' is not usable. No logging possible (error: \'%s\')', $file, $exception->getMessage());
61                         }
62                 }
63
64                 return null;
65         }
66
67         /** {@inheritDoc} */
68         public function checkDebugLogfile(): ?string
69         {
70                 // Check logfile permission
71                 if ($this->config->get('system', 'debugging')) {
72                         $file = $this->config->get('system', 'dlogfile');
73
74                         if (empty($file)) {
75                                 return null;
76                         }
77
78                         try {
79                                 $stream = $this->fileSystem->createStream($file);
80
81                                 if (!isset($stream)) {
82                                         throw new LoggerUnusableException('Stream is null.');
83                                 }
84                         } catch (\Throwable $exception) {
85                                 return $this->l10n->t('The debug logfile \'%s\' is not usable. No logging possible (error: \'%s\')', $file, $exception->getMessage());
86                         }
87                 }
88
89                 return null;
90         }
91 }