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;
25 use Friendica\Core\Theme;
27 use Friendica\Module\BaseAdmin;
30 class View extends BaseAdmin
34 protected function content(array $request = []): string
38 $t = Renderer::getMarkupTemplate('admin/logs/view.tpl');
39 DI::page()->registerFooterScript(Theme::getPathForFile('js/module/admin/logs/view.js'));
41 $f = DI::config()->get('system', 'logfile');
45 $search = $_GET['q'] ?? '';
47 $filters_valid_values = [
57 'context' => ['', 'index', 'worker'],
60 'level' => $_GET['level'] ?? '',
61 'context' => $_GET['context'] ?? '',
63 foreach ($filters as $k => $v) {
64 if ($v == '' || !in_array($v, $filters_valid_values[$k])) {
69 if (!file_exists($f)) {
70 $error = DI::l10n()->t('Error trying to open <strong>%1$s</strong> log file.<br/>Check to see if file %1$s exist and is readable.', $f);
73 $data = DI::parsedLogIterator()
75 ->withLimit(self::LIMIT)
76 ->withFilters($filters)
77 ->withSearch($search);
78 } catch (\Exception $e) {
79 $error = DI::l10n()->t('Couldn\'t open <strong>%1$s</strong> log file.<br/>Check to see if file %1$s is readable.', $f);
82 return Renderer::replaceMacros($t, [
83 '$baseurl' => DI::baseUrl()->get(true),
84 '$title' => DI::l10n()->t('Administration'),
85 '$page' => DI::l10n()->t('View Logs'),
87 'Search' => DI::l10n()->t('Search'),
88 'Search_in_logs' => DI::l10n()->t('Search in logs'),
89 'Show_all' => DI::l10n()->t('Show all'),
90 'Date' => DI::l10n()->t('Date'),
91 'Level' => DI::l10n()->t('Level'),
92 'Context' => DI::l10n()->t('Context'),
93 'Message' => DI::l10n()->t('Message'),
94 'ALL' => DI::l10n()->t('ALL'),
95 'View_details' => DI::l10n()->t('View details'),
96 'Click_to_view_details' => DI::l10n()->t('Click to view details'),
97 'Event_details' => DI::l10n()->t('Event details'),
98 'Data' => DI::l10n()->t('Data'),
99 'Source' => DI::l10n()->t('Source'),
100 'File' => DI::l10n()->t('File'),
101 'Line' => DI::l10n()->t('Line'),
102 'Function' => DI::l10n()->t('Function'),
103 'UID' => DI::l10n()->t('UID'),
104 'Process_ID' => DI::l10n()->t('Process ID'),
105 'Close' => DI::l10n()->t('Close'),
109 '$filters' => $filters,
110 '$filtersvalues' => $filters_valid_values,
112 '$logname' => DI::config()->get('system', 'logfile'),