]> git.mxchange.org Git - friendica.git/blob - src/Module/Admin/Logs/Settings.php
Merge pull request #7095 from annando/ap-connect
[friendica.git] / src / Module / Admin / Logs / Settings.php
1 <?php
2
3 namespace Friendica\Module\Admin\Logs;
4
5 use Friendica\Core\Config;
6 use Friendica\Core\L10n;
7 use Friendica\Core\Renderer;
8 use Friendica\Module\BaseAdminModule;
9 use Friendica\Util\Strings;
10 use Psr\Log\LogLevel;
11
12 class Settings extends BaseAdminModule
13 {
14         public static function post()
15         {
16                 parent::post();
17
18                 if (!empty($_POST['page_logs'])) {
19                         parent::checkFormSecurityTokenRedirectOnError('/admin/logs', 'admin_logs');
20
21                         $logfile   = (!empty($_POST['logfile']) ? Strings::escapeTags(trim($_POST['logfile'])) : '');
22                         $debugging = !empty($_POST['debugging']);
23                         $loglevel  = defaults($_POST, 'loglevel', LogLevel::ERROR);
24
25                         Config::set('system', 'logfile', $logfile);
26                         Config::set('system', 'debugging', $debugging);
27                         Config::set('system', 'loglevel', $loglevel);
28                 }
29
30                 info(L10n::t("Log settings updated."));
31                 self::getApp()->internalRedirect('admin/logs');
32         }
33
34         public static function content()
35         {
36                 parent::content();
37
38                 $a = self::getApp();
39
40                 $log_choices = [
41                         LogLevel::ERROR   => 'Error',
42                         LogLevel::WARNING => 'Warning',
43                         LogLevel::NOTICE  => 'Notice',
44                         LogLevel::INFO    => 'Info',
45                         LogLevel::DEBUG   => 'Debug',
46                 ];
47
48                 if (ini_get('log_errors')) {
49                         $phplogenabled = L10n::t('PHP log currently enabled.');
50                 } else {
51                         $phplogenabled = L10n::t('PHP log currently disabled.');
52                 }
53
54                 $t = Renderer::getMarkupTemplate('admin/logs/settings.tpl');
55
56                 return Renderer::replaceMacros($t, [
57                         '$title' => L10n::t('Administration'),
58                         '$page' => L10n::t('Logs'),
59                         '$submit' => L10n::t('Save Settings'),
60                         '$clear' => L10n::t('Clear'),
61                         '$baseurl' => $a->getBaseURL(true),
62                         '$logname' => Config::get('system', 'logfile'),
63                         // see /help/smarty3-templates#1_1 on any Friendica node
64                         '$debugging' => ['debugging', L10n::t("Enable Debugging"), Config::get('system', 'debugging'), ""],
65                         '$logfile' => ['logfile', L10n::t("Log file"), Config::get('system', 'logfile'), L10n::t("Must be writable by web server. Relative to your Friendica top-level directory.")],
66                         '$loglevel' => ['loglevel', L10n::t("Log level"), Config::get('system', 'loglevel'), "", $log_choices],
67                         '$form_security_token' => parent::getFormSecurityToken("admin_logs"),
68                         '$phpheader' => L10n::t("PHP logging"),
69                         '$phphint' => 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."),
70                         '$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');",
71                         '$phplogenabled' => $phplogenabled,
72                 ]);
73         }
74 }