6ef7d09c70bd7ff94343515a29cd38bd5d853e36
[project/luci.git] / modules / luci-mod-status / htdocs / luci-static / resources / view / status / syslog.js
1 'use strict';
2 'require view';
3 'require fs';
4 'require ui';
5
6 return view.extend({
7 load: function() {
8 return Promise.all([
9 L.resolveDefault(fs.stat('/sbin/logread'), null),
10 L.resolveDefault(fs.stat('/usr/sbin/logread'), null)
11 ]).then(function(stat) {
12 var logger = stat[0] ? stat[0].path : stat[1] ? stat[1].path : null;
13
14 return fs.exec_direct(logger, [ '-e', '^' ]).catch(function(err) {
15 ui.addNotification(null, E('p', {}, _('Unable to load log data: ' + err.message)));
16 return '';
17 });
18 });
19 },
20
21 render: function(logdata) {
22 var loglines = logdata.trim().split(/\n/);
23
24
25 var scrollDownButton = E('button', {
26 'id': 'scrollDownButton',
27 'class': 'cbi-button cbi-button-neutral'
28 }, _('Scroll to tail', 'scroll to bottom (the tail) of the log file')
29 );
30 scrollDownButton.addEventListener('click', function() {
31 scrollUpButton.focus();
32 });
33
34 var scrollUpButton = E('button', {
35 'id' : 'scrollUpButton',
36 'class': 'cbi-button cbi-button-neutral'
37 }, _('Scroll to head', 'scroll to top (the head) of the log file')
38 );
39 scrollUpButton.addEventListener('click', function() {
40 scrollDownButton.focus();
41 });
42
43 return E([], [
44 E('h2', {}, [ _('System Log') ]),
45 E('div', { 'id': 'content_syslog' }, [
46 E('div', {'style': 'padding-bottom: 20px'}, [scrollDownButton]),
47 E('textarea', {
48 'id': 'syslog',
49 'style': 'font-size:12px',
50 'readonly': 'readonly',
51 'wrap': 'off',
52 'rows': loglines.length + 1
53 }, [ loglines.join('\n') ]),
54 E('div', {'style': 'padding-bottom: 20px'}, [scrollUpButton])
55 ])
56 ]);
57 },
58
59 handleSaveApply: null,
60 handleSave: null,
61 handleReset: null
62 });