luci-mod-status: auto-refresh system log and kernel log 7101/head
authorDaniel Nilsson <daniel.nilsson94@outlook.com>
Tue, 23 Apr 2024 19:52:54 +0000 (21:52 +0200)
committerDaniel Nilsson <daniel.nilsson94@outlook.com>
Wed, 1 May 2024 16:10:12 +0000 (18:10 +0200)
Signed-off-by: Daniel Nilsson <daniel.nilsson94@outlook.com>
modules/luci-mod-status/htdocs/luci-static/resources/view/status/dmesg.js
modules/luci-mod-status/htdocs/luci-static/resources/view/status/syslog.js

index acddf454f58c1a50507e4be187f45cee4fd5ea02..45b483962d5f1a4e6b0a2e597de4801fa704a83e 100644 (file)
@@ -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])
                        ])
                ]);
index 6ef7d09c70bd7ff94343515a29cd38bd5d853e36..2e3d705c222059609dba6918f1b15b9d82b4bd86 100644 (file)
@@ -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])
                        ])
                ]);