event log: add pagination

This commit is contained in:
Andrew Dolgov 2021-02-06 10:10:54 +03:00
parent 9fdeb58fd3
commit 10392ecc28
4 changed files with 114 additions and 79 deletions

View File

@ -23,42 +23,7 @@ class Pref_System extends Handler_Protected {
$this->pdo->query("DELETE FROM ttrss_error_log"); $this->pdo->query("DELETE FROM ttrss_error_log");
} }
function index() { private function log_viewer(int $page, int $severity) {
$severity = isset($_REQUEST["severity"]) ? (int) clean($_REQUEST["severity"]) : E_USER_WARNING;
print "<div dojoType='dijit.layout.AccordionContainer' region='center'>";
print "<div dojoType='dijit.layout.AccordionPane' style='padding : 0'
title='<i class=\"material-icons\">report</i> ".__('Event Log')."'>";
if (LOG_DESTINATION == "sql") {
print "<div dojoType='dijit.layout.BorderContainer' gutters='false'>";
print "<div region='top' dojoType='fox.Toolbar'>";
print "<button dojoType='dijit.form.Button'
onclick='Helpers.updateEventLog()'>".__('Refresh')."</button>";
print "<button dojoType='dijit.form.Button'
onclick='Helpers.clearEventLog()'>".__('Clear')."</button>";
print "<div class='pull-right'>";
print __("Severity:") . " ";
print_select_hash("severity", $severity,
[
E_USER_ERROR => __("Errors"),
E_USER_WARNING => __("Warnings"),
E_USER_NOTICE => __("Everything")
], 'dojoType="fox.form.Select" onchange="Helpers.updateEventLog()"');
print "</div>"; # pull-right
print "</div>"; # toolbar
print '<div style="padding : 0px" dojoType="dijit.layout.ContentPane" region="center">';
print "<table width='100%' cellspacing='10' class='prefErrorLog'>"; print "<table width='100%' cellspacing='10' class='prefErrorLog'>";
print "<tr class='title'> print "<tr class='title'>
@ -87,6 +52,9 @@ class Pref_System extends Handler_Protected {
$errno_filter_qpart = "true"; $errno_filter_qpart = "true";
} }
$limit = 10;
$offset = $limit * $page;
$sth = $this->pdo->prepare("SELECT $sth = $this->pdo->prepare("SELECT
errno, errstr, filename, lineno, created_at, login, context errno, errstr, filename, lineno, created_at, login, context
FROM FROM
@ -95,7 +63,7 @@ class Pref_System extends Handler_Protected {
$errno_filter_qpart $errno_filter_qpart
ORDER BY ORDER BY
ttrss_error_log.id DESC ttrss_error_log.id DESC
LIMIT 100"); LIMIT $limit OFFSET $offset");
$sth->execute($errno_values); $sth->execute($errno_values);
@ -118,6 +86,55 @@ class Pref_System extends Handler_Protected {
} }
print "</table>"; print "</table>";
}
function index() {
$severity = (int) ($_REQUEST["severity"] ?? E_USER_WARNING);
$page = (int) ($_REQUEST["page"] ?? 0);
print "<div dojoType='dijit.layout.AccordionContainer' region='center'>";
print "<div dojoType='dijit.layout.AccordionPane' style='padding : 0'
title='<i class=\"material-icons\">report</i> ".__('Event Log')."'>";
if (LOG_DESTINATION == "sql") {
print "<div dojoType='dijit.layout.BorderContainer' gutters='false'>";
print "<div region='top' dojoType='fox.Toolbar'>";
print "<button dojoType='dijit.form.Button'
onclick='Helpers.EventLog.refresh()'>".__('Refresh')."</button>";
print "<button dojoType='dijit.form.Button'
onclick='Helpers.EventLog.prevPage()'>".__('&lt;&lt;')."</button>";
print "<button dojoType='dijit.form.Button' disabled>".T_sprintf('Page %d', $page+1)."</button>";
print "<button dojoType='dijit.form.Button'
onclick='Helpers.EventLog.nextPage()'>".__('&gt;&gt;')."</button>";
print "<button dojoType='dijit.form.Button'
onclick='Helpers.EventLog.clear()'>".__('Clear')."</button>";
print "<div class='pull-right'>";
print __("Severity:") . " ";
print_select_hash("severity", $severity,
[
E_USER_ERROR => __("Errors"),
E_USER_WARNING => __("Warnings"),
E_USER_NOTICE => __("Everything")
], 'dojoType="fox.form.Select" onchange="Helpers.updateEventLog()"');
print "</div>"; # pull-right
print "</div>"; # toolbar
print '<div style="padding : 0px" dojoType="dijit.layout.ContentPane" region="center">';
$this->log_viewer($page, $severity);
} else { } else {
print_notice("Please set LOG_DESTINATION to 'sql' in config.php to enable database logging."); print_notice("Please set LOG_DESTINATION to 'sql' in config.php to enable database logging.");
} }

View File

@ -54,7 +54,9 @@ class Sanitizer {
} }
public static function sanitize($str, $force_remove_images = false, $owner = false, $site_url = false, $highlight_words = false, $article_id = false) { public static function sanitize($str, $force_remove_images = false, $owner = false, $site_url = false, $highlight_words = false, $article_id = false) {
if (!$owner) $owner = $_SESSION["uid"];
if (!$owner && isset($_SESSION["uid"]))
$owner = $_SESSION["uid"];
$res = trim($str); if (!$res) return ''; $res = trim($str); if (!$res) return '';

View File

@ -11,11 +11,11 @@ function format_backtrace($trace) {
if (is_array($e["args"])) { if (is_array($e["args"])) {
foreach ($e["args"] as $a) { foreach ($e["args"] as $a) {
if (is_object($a)) { if (is_object($a)) {
array_push($fmt_args, "[" . get_class($a) . "]"); array_push($fmt_args, "{" . get_class($a) . "}");
} else if (is_array($a)) { } else if (is_array($a)) {
array_push($fmt_args, "[" . truncate_string(json_encode($a), 128, "...")) . "]"; array_push($fmt_args, "[" . truncate_string(json_encode($a), 256, "...")) . "]";
} else { } else {
array_push($fmt_args, $a); array_push($fmt_args, truncate_string($a, 256, "..."));
} }
} }
} }

View File

@ -50,22 +50,38 @@ const Helpers = {
return false; return false;
}, },
updateEventLog: function() { EventLog: {
xhrPost("backend.php", { op: "pref-system", severity: dijit.byId("severity").attr('value') }, (transport) => { log_page: 0,
refresh: function() {
this.log_page = 0;
this.update();
},
update: function() {
xhrPost("backend.php", { op: "pref-system", severity: dijit.byId("severity").attr('value'), page: Helpers.EventLog.log_page }, (transport) => {
dijit.byId('systemConfigTab').attr('content', transport.responseText); dijit.byId('systemConfigTab').attr('content', transport.responseText);
Notify.close(); Notify.close();
}); });
}, },
clearEventLog: function() { nextPage: function() {
this.log_page += 1;
this.update();
},
prevPage: function() {
if (this.log_page > 0) this.log_page -= 1;
this.update();
},
clear: function() {
if (confirm(__("Clear event log?"))) { if (confirm(__("Clear event log?"))) {
Notify.progress("Loading, please wait..."); Notify.progress("Loading, please wait...");
xhrPost("backend.php", {op: "pref-system", method: "clearLog"}, () => { xhrPost("backend.php", {op: "pref-system", method: "clearLog"}, () => {
this.updateEventLog(); Helpers.EventLog.refresh();
}); });
} }
}, },
},
editProfiles: function() { editProfiles: function() {
if (dijit.byId("profileEditDlg")) if (dijit.byId("profileEditDlg"))