3 * @copyright Copyright (C) 2020, Friendica
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;
27 use Friendica\Util\Strings;
30 class Settings extends BaseAdmin
32 public static function post(array $parameters = [])
34 self::checkAdminAccess();
36 if (empty($_POST['page_logs'])) {
40 self::checkFormSecurityTokenRedirectOnError('/admin/logs', 'admin_logs');
42 $logfile = (!empty($_POST['logfile']) ? Strings::escapeTags(trim($_POST['logfile'])) : '');
43 $debugging = !empty($_POST['debugging']);
44 $loglevel = ($_POST['loglevel'] ?? '') ?: LogLevel::ERROR;
46 if (is_file($logfile) &&
47 !is_writeable($logfile)) {
48 notice(DI::l10n()->t('The logfile \'%s\' is not writable. No logging possible', $logfile));
52 DI::config()->set('system', 'logfile', $logfile);
53 DI::config()->set('system', 'debugging', $debugging);
54 DI::config()->set('system', 'loglevel', $loglevel);
56 DI::baseUrl()->redirect('admin/logs');
59 public static function content(array $parameters = [])
61 parent::content($parameters);
64 LogLevel::ERROR => 'Error',
65 LogLevel::WARNING => 'Warning',
66 LogLevel::NOTICE => 'Notice',
67 LogLevel::INFO => 'Info',
68 LogLevel::DEBUG => 'Debug',
71 if (ini_get('log_errors')) {
72 $phplogenabled = DI::l10n()->t('PHP log currently enabled.');
74 $phplogenabled = DI::l10n()->t('PHP log currently disabled.');
77 $t = Renderer::getMarkupTemplate('admin/logs/settings.tpl');
79 return Renderer::replaceMacros($t, [
80 '$title' => DI::l10n()->t('Administration'),
81 '$page' => DI::l10n()->t('Logs'),
82 '$submit' => DI::l10n()->t('Save Settings'),
83 '$clear' => DI::l10n()->t('Clear'),
84 '$baseurl' => DI::baseUrl()->get(true),
85 '$logname' => DI::config()->get('system', 'logfile'),
86 // see /help/smarty3-templates#1_1 on any Friendica node
87 '$debugging' => ['debugging', DI::l10n()->t("Enable Debugging"), DI::config()->get('system', 'debugging'), ""],
88 '$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.")],
89 '$loglevel' => ['loglevel', DI::l10n()->t("Log level"), DI::config()->get('system', 'loglevel'), "", $log_choices],
90 '$form_security_token' => self::getFormSecurityToken("admin_logs"),
91 '$phpheader' => DI::l10n()->t("PHP logging"),
92 '$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."),
93 '$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');",
94 '$phplogenabled' => $phplogenabled,