diff options
author | Daniel Nilsson <daniel.nilsson94@outlook.com> | 2024-04-23 21:52:54 +0200 |
---|---|---|
committer | Daniel Nilsson <daniel.nilsson94@outlook.com> | 2024-05-01 18:10:12 +0200 |
commit | 9fcb7d332b1c9b8b00a67241fcbaaf4fc4a8e5bf (patch) | |
tree | 3cd4b5709ece09db7b9448793eb98ef61d2abf85 /modules/luci-mod-status/htdocs/luci-static/resources/view/status/dmesg.js | |
parent | fa2aeb7d2ff84c0dc022c7432b6123cb950dbd61 (diff) |
luci-mod-status: auto-refresh system log and kernel log
Signed-off-by: Daniel Nilsson <daniel.nilsson94@outlook.com>
Diffstat (limited to 'modules/luci-mod-status/htdocs/luci-static/resources/view/status/dmesg.js')
-rw-r--r-- | modules/luci-mod-status/htdocs/luci-static/resources/view/status/dmesg.js | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/modules/luci-mod-status/htdocs/luci-static/resources/view/status/dmesg.js b/modules/luci-mod-status/htdocs/luci-static/resources/view/status/dmesg.js index acddf454f5..45b483962d 100644 --- a/modules/luci-mod-status/htdocs/luci-static/resources/view/status/dmesg.js +++ b/modules/luci-mod-status/htdocs/luci-static/resources/view/status/dmesg.js @@ -1,21 +1,37 @@ 'use strict'; 'require view'; 'require fs'; +'require poll'; 'require ui'; return view.extend({ - load: function() { - return fs.exec_direct('/bin/dmesg', [ '-r' ]).catch(function(err) { + retrieveLog: async function() { + return fs.exec_direct('/bin/dmesg', [ '-r' ]).then(logdata => { + const loglines = logdata.trim().split(/\n/).map(function(line) { + return line.replace(/^<\d+>/, ''); + }); + 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/).map(function(line) { - return line.replace(/^<\d+>/, ''); - }); + 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', @@ -43,8 +59,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]) ]) ]); |