mirror of https://git.openwrt.org/project/luci.git
luci-mod-status: auto-refresh system log and kernel log
Signed-off-by: Daniel Nilsson <daniel.nilsson94@outlook.com>
This commit is contained in:
parent
fa2aeb7d2f
commit
9fcb7d332b
|
@ -1,21 +1,37 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
'require view';
|
'require view';
|
||||||
'require fs';
|
'require fs';
|
||||||
|
'require poll';
|
||||||
'require ui';
|
'require ui';
|
||||||
|
|
||||||
return view.extend({
|
return view.extend({
|
||||||
load: function() {
|
retrieveLog: async function() {
|
||||||
return fs.exec_direct('/bin/dmesg', [ '-r' ]).catch(function(err) {
|
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)));
|
ui.addNotification(null, E('p', {}, _('Unable to load log data: ' + err.message)));
|
||||||
return '';
|
return '';
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function(logdata) {
|
pollLog: async function() {
|
||||||
var loglines = logdata.trim().split(/\n/).map(function(line) {
|
const element = document.getElementById('syslog');
|
||||||
return line.replace(/^<\d+>/, '');
|
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', {
|
var scrollDownButton = E('button', {
|
||||||
'id': 'scrollDownButton',
|
'id': 'scrollDownButton',
|
||||||
'class': 'cbi-button cbi-button-neutral',
|
'class': 'cbi-button cbi-button-neutral',
|
||||||
|
@ -43,8 +59,8 @@ return view.extend({
|
||||||
'style': 'font-size:12px',
|
'style': 'font-size:12px',
|
||||||
'readonly': 'readonly',
|
'readonly': 'readonly',
|
||||||
'wrap': 'off',
|
'wrap': 'off',
|
||||||
'rows': loglines.length + 1
|
'rows': loglines.rows
|
||||||
}, [ loglines.join('\n') ]),
|
}, [ loglines.value ]),
|
||||||
E('div', {'style': 'padding-bottom: 20px'}, [scrollUpButton])
|
E('div', {'style': 'padding-bottom: 20px'}, [scrollUpButton])
|
||||||
])
|
])
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -1,27 +1,42 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
'require view';
|
'require view';
|
||||||
'require fs';
|
'require fs';
|
||||||
|
'require poll';
|
||||||
'require ui';
|
'require ui';
|
||||||
|
|
||||||
return view.extend({
|
return view.extend({
|
||||||
load: function() {
|
retrieveLog: async function() {
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
L.resolveDefault(fs.stat('/sbin/logread'), null),
|
L.resolveDefault(fs.stat('/sbin/logread'), null),
|
||||||
L.resolveDefault(fs.stat('/usr/sbin/logread'), null)
|
L.resolveDefault(fs.stat('/usr/sbin/logread'), null)
|
||||||
]).then(function(stat) {
|
]).then(function(stat) {
|
||||||
var logger = stat[0] ? stat[0].path : stat[1] ? stat[1].path : null;
|
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)));
|
ui.addNotification(null, E('p', {}, _('Unable to load log data: ' + err.message)));
|
||||||
return '';
|
return '';
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function(logdata) {
|
pollLog: async function() {
|
||||||
var loglines = logdata.trim().split(/\n/);
|
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', {
|
var scrollDownButton = E('button', {
|
||||||
'id': 'scrollDownButton',
|
'id': 'scrollDownButton',
|
||||||
'class': 'cbi-button cbi-button-neutral'
|
'class': 'cbi-button cbi-button-neutral'
|
||||||
|
@ -49,8 +64,8 @@ return view.extend({
|
||||||
'style': 'font-size:12px',
|
'style': 'font-size:12px',
|
||||||
'readonly': 'readonly',
|
'readonly': 'readonly',
|
||||||
'wrap': 'off',
|
'wrap': 'off',
|
||||||
'rows': loglines.length + 1
|
'rows': loglines.rows,
|
||||||
}, [ loglines.join('\n') ]),
|
}, [ loglines.value ]),
|
||||||
E('div', {'style': 'padding-bottom: 20px'}, [scrollUpButton])
|
E('div', {'style': 'padding-bottom: 20px'}, [scrollUpButton])
|
||||||
])
|
])
|
||||||
]);
|
]);
|
||||||
|
|
Loading…
Reference in New Issue