3 namespace Friendica\Module\Admin\Logs;
5 use Friendica\Core\Config;
6 use Friendica\Core\Renderer;
8 use Friendica\Module\BaseAdminModule;
9 use Friendica\Util\Strings;
12 class Settings extends BaseAdminModule
14 public static function post(array $parameters = [])
16 parent::post($parameters);
18 if (!empty($_POST['page_logs'])) {
19 parent::checkFormSecurityTokenRedirectOnError('/admin/logs', 'admin_logs');
21 $logfile = (!empty($_POST['logfile']) ? Strings::escapeTags(trim($_POST['logfile'])) : '');
22 $debugging = !empty($_POST['debugging']);
23 $loglevel = ($_POST['loglevel'] ?? '') ?: LogLevel::ERROR;
25 if (is_file($logfile) &&
26 !is_writeable($logfile)) {
27 notice(DI::l10n()->t('The logfile \'%s\' is not writable. No logging possible', $logfile));
31 DI::config()->set('system', 'logfile', $logfile);
32 DI::config()->set('system', 'debugging', $debugging);
33 DI::config()->set('system', 'loglevel', $loglevel);
36 info(DI::l10n()->t("Log settings updated."));
37 DI::baseUrl()->redirect('admin/logs');
40 public static function content(array $parameters = [])
42 parent::content($parameters);
45 LogLevel::ERROR => 'Error',
46 LogLevel::WARNING => 'Warning',
47 LogLevel::NOTICE => 'Notice',
48 LogLevel::INFO => 'Info',
49 LogLevel::DEBUG => 'Debug',
52 if (ini_get('log_errors')) {
53 $phplogenabled = DI::l10n()->t('PHP log currently enabled.');
55 $phplogenabled = DI::l10n()->t('PHP log currently disabled.');
58 $t = Renderer::getMarkupTemplate('admin/logs/settings.tpl');
60 return Renderer::replaceMacros($t, [
61 '$title' => DI::l10n()->t('Administration'),
62 '$page' => DI::l10n()->t('Logs'),
63 '$submit' => DI::l10n()->t('Save Settings'),
64 '$clear' => DI::l10n()->t('Clear'),
65 '$baseurl' => DI::baseUrl()->get(true),
66 '$logname' => DI::config()->get('system', 'logfile'),
67 // see /help/smarty3-templates#1_1 on any Friendica node
68 '$debugging' => ['debugging', DI::l10n()->t("Enable Debugging"), DI::config()->get('system', 'debugging'), ""],
69 '$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.")],
70 '$loglevel' => ['loglevel', DI::l10n()->t("Log level"), DI::config()->get('system', 'loglevel'), "", $log_choices],
71 '$form_security_token' => parent::getFormSecurityToken("admin_logs"),
72 '$phpheader' => DI::l10n()->t("PHP logging"),
73 '$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."),
74 '$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');",
75 '$phplogenabled' => $phplogenabled,