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\Module\Admin\Logs;
24 use Friendica\Core\Renderer;
26 use Friendica\Module\BaseAdmin;
29 class Settings extends BaseAdmin
31 protected function post(array $request = [])
33 self::checkAdminAccess();
35 if (empty($_POST['page_logs'])) {
39 self::checkFormSecurityTokenRedirectOnError('/admin/logs', 'admin_logs');
41 $logfile = (!empty($_POST['logfile']) ? trim($_POST['logfile']) : '');
42 $debugging = !empty($_POST['debugging']);
43 $loglevel = ($_POST['loglevel'] ?? '') ?: LogLevel::ERROR;
45 if (is_file($logfile) &&
46 !is_writeable($logfile)) {
47 DI::sysmsg()->addNotice(DI::l10n()->t('The logfile \'%s\' is not writable. No logging possible', $logfile));
51 DI::config()->set('system', 'logfile', $logfile);
52 DI::config()->set('system', 'debugging', $debugging);
53 DI::config()->set('system', 'loglevel', $loglevel);
55 DI::baseUrl()->redirect('admin/logs');
58 protected function content(array $request = []): string
63 LogLevel::ERROR => 'Error',
64 LogLevel::WARNING => 'Warning',
65 LogLevel::NOTICE => 'Notice',
66 LogLevel::INFO => 'Info',
67 LogLevel::DEBUG => 'Debug',
70 if (ini_get('log_errors')) {
71 $phplogenabled = DI::l10n()->t('PHP log currently enabled.');
73 $phplogenabled = DI::l10n()->t('PHP log currently disabled.');
76 $t = Renderer::getMarkupTemplate('admin/logs/settings.tpl');
78 return Renderer::replaceMacros($t, [
79 '$title' => DI::l10n()->t('Administration'),
80 '$page' => DI::l10n()->t('Logs'),
81 '$submit' => DI::l10n()->t('Save Settings'),
82 '$clear' => DI::l10n()->t('Clear'),
83 '$logname' => DI::config()->get('system', 'logfile'),
84 // see /help/smarty3-templates#1_1 on any Friendica node
85 '$debugging' => ['debugging', DI::l10n()->t("Enable Debugging"), DI::config()->get('system', 'debugging'), ""],
86 '$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.")],
87 '$loglevel' => ['loglevel', DI::l10n()->t("Log level"), DI::config()->get('system', 'loglevel'), "", $log_choices],
88 '$form_security_token' => self::getFormSecurityToken("admin_logs"),
89 '$phpheader' => DI::l10n()->t("PHP logging"),
90 '$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."),
91 '$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');",
92 '$phplogenabled' => $phplogenabled,