]> git.mxchange.org Git - friendica.git/blob - src/Module/Admin/Logs/Settings.php
b8e588cd7d15308a3560504fbdbafa82e1d1191d
[friendica.git] / src / Module / Admin / Logs / Settings.php
1 <?php
2
3 namespace Friendica\Module\Admin\Logs;
4
5 use Friendica\Core\Renderer;
6 use Friendica\DI;
7 use Friendica\Module\BaseAdmin;
8 use Friendica\Util\Strings;
9 use Psr\Log\LogLevel;
10
11 class Settings extends BaseAdmin
12 {
13         public static function post(array $parameters = [])
14         {
15                 parent::post($parameters);
16
17                 if (!empty($_POST['page_logs'])) {
18                         parent::checkFormSecurityTokenRedirectOnError('/admin/logs', 'admin_logs');
19
20                         $logfile   = (!empty($_POST['logfile']) ? Strings::escapeTags(trim($_POST['logfile'])) : '');
21                         $debugging = !empty($_POST['debugging']);
22                         $loglevel  = ($_POST['loglevel'] ?? '') ?: LogLevel::ERROR;
23
24                         if (is_file($logfile) &&
25                         !is_writeable($logfile)) {
26                                 notice(DI::l10n()->t('The logfile \'%s\' is not writable. No logging possible', $logfile));
27                                 return;
28                         }
29
30                         DI::config()->set('system', 'logfile', $logfile);
31                         DI::config()->set('system', 'debugging', $debugging);
32                         DI::config()->set('system', 'loglevel', $loglevel);
33                 }
34
35                 info(DI::l10n()->t("Log settings updated."));
36                 DI::baseUrl()->redirect('admin/logs');
37         }
38
39         public static function content(array $parameters = [])
40         {
41                 parent::content($parameters);
42
43                 $log_choices = [
44                         LogLevel::ERROR   => 'Error',
45                         LogLevel::WARNING => 'Warning',
46                         LogLevel::NOTICE  => 'Notice',
47                         LogLevel::INFO    => 'Info',
48                         LogLevel::DEBUG   => 'Debug',
49                 ];
50
51                 if (ini_get('log_errors')) {
52                         $phplogenabled = DI::l10n()->t('PHP log currently enabled.');
53                 } else {
54                         $phplogenabled = DI::l10n()->t('PHP log currently disabled.');
55                 }
56
57                 $t = Renderer::getMarkupTemplate('admin/logs/settings.tpl');
58
59                 return Renderer::replaceMacros($t, [
60                         '$title' => DI::l10n()->t('Administration'),
61                         '$page' => DI::l10n()->t('Logs'),
62                         '$submit' => DI::l10n()->t('Save Settings'),
63                         '$clear' => DI::l10n()->t('Clear'),
64                         '$baseurl' => DI::baseUrl()->get(true),
65                         '$logname' => DI::config()->get('system', 'logfile'),
66                         // see /help/smarty3-templates#1_1 on any Friendica node
67                         '$debugging' => ['debugging', DI::l10n()->t("Enable Debugging"), DI::config()->get('system', 'debugging'), ""],
68                         '$logfile' => ['logfile', DI::l10n()->t("Log file"), DI::config()->get('system', 'logfile'), DI::l10n()->t("Must be writable by web server. Relative to your Friendica top-level directory.")],
69                         '$loglevel' => ['loglevel', DI::l10n()->t("Log level"), DI::config()->get('system', 'loglevel'), "", $log_choices],
70                         '$form_security_token' => parent::getFormSecurityToken("admin_logs"),
71                         '$phpheader' => DI::l10n()->t("PHP logging"),
72                         '$phphint' => DI::l10n()->t("To temporarily enable logging of PHP errors and warnings you can prepend the following to the index.php file of your installation. The filename set in the 'error_log' line is relative to the friendica top-level directory and must be writeable by the web server. The option '1' for 'log_errors' and 'display_errors' is to enable these options, set to '0' to disable them."),
73                         '$phplogcode' => "error_reporting(E_ERROR | E_WARNING | E_PARSE);\nini_set('error_log','php.out');\nini_set('log_errors','1');\nini_set('display_errors', '1');",
74                         '$phplogenabled' => $phplogenabled,
75                 ]);
76         }
77 }