From 9fcb7d332b1c9b8b00a67241fcbaaf4fc4a8e5bf Mon Sep 17 00:00:00 2001 From: Daniel Nilsson Date: Tue, 23 Apr 2024 21:52:54 +0200 Subject: luci-mod-status: auto-refresh system log and kernel log Signed-off-by: Daniel Nilsson --- .../luci-static/resources/view/status/syslog.js | 27 +++++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'modules/luci-mod-status/htdocs/luci-static/resources/view/status/syslog.js') diff --git a/modules/luci-mod-status/htdocs/luci-static/resources/view/status/syslog.js b/modules/luci-mod-status/htdocs/luci-static/resources/view/status/syslog.js index 6ef7d09c70..2e3d705c22 100644 --- a/modules/luci-mod-status/htdocs/luci-static/resources/view/status/syslog.js +++ b/modules/luci-mod-status/htdocs/luci-static/resources/view/status/syslog.js @@ -1,27 +1,42 @@ 'use strict'; 'require view'; 'require fs'; +'require poll'; 'require ui'; return view.extend({ - load: function() { + retrieveLog: async function() { return Promise.all([ L.resolveDefault(fs.stat('/sbin/logread'), null), L.resolveDefault(fs.stat('/usr/sbin/logread'), null) ]).then(function(stat) { var logger = stat[0] ? stat[0].path : stat[1] ? stat[1].path : null; - return fs.exec_direct(logger, [ '-e', '^' ]).catch(function(err) { + return fs.exec_direct(logger, [ '-e', '^' ]).then(logdata => { + const loglines = logdata.trim().split(/\n/); + return { value: loglines.join('\n'), rows: loglines.length + 1 }; + }).catch(function(err) { ui.addNotification(null, E('p', {}, _('Unable to load log data: ' + err.message))); return ''; }); }); }, - render: function(logdata) { - var loglines = logdata.trim().split(/\n/); + pollLog: async function() { + const element = document.getElementById('syslog'); + if (element) { + const log = await this.retrieveLog(); + element.value = log.value; + element.rows = log.rows; + } + }, + load: async function() { + poll.add(this.pollLog.bind(this)); + return await this.retrieveLog(); + }, + render: function(loglines) { var scrollDownButton = E('button', { 'id': 'scrollDownButton', 'class': 'cbi-button cbi-button-neutral' @@ -49,8 +64,8 @@ return view.extend({ 'style': 'font-size:12px', 'readonly': 'readonly', 'wrap': 'off', - 'rows': loglines.length + 1 - }, [ loglines.join('\n') ]), + 'rows': loglines.rows, + }, [ loglines.value ]), E('div', {'style': 'padding-bottom: 20px'}, [scrollUpButton]) ]) ]); -- cgit v1.2.3