1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
|
'use strict';
'require view';
'require fs';
'require poll';
'require ui';
return view.extend({
logFilterFrom: '0',
logFilterTo: '',
invertLogRangeFilter: false,
minSeverity: '',
invertMinSeverity: false,
sortLogsDescending: false,
logTextFilter: '',
invertLogTextSearch: false,
severity: [
['', 'KERN_DEFAULT', _('Default')],
// ['0', 'KERN_EMERG'], // unusable kernels tend to halt ergo no running system
['1', 'KERN_ALERT', _('Alert')],
['2', 'KERN_CRIT', _('Critical')],
['3', 'KERN_ERR', _('Error')],
['4', 'KERN_WARNING', _('Warning')],
['5', 'KERN_NOTICE', _('Notice')],
['6', 'KERN_INFO', _('Info')],
['7', 'KERN_DEBUG', _('Debug')],
// ['c', 'KERN_CONT'], // for follow-on printed lines lacking newline
/*
As of 24.10 there appear to be kernel log lines printed with severity 14-15
which seems like a bug in ubox. So we must structure the filter in an
'at least' fashion to include those.
*/
],
async retrieveLog() {
return fs.exec_direct('/bin/dmesg', [ '-r' ]).then(logdata => {
let loglines = [];
let lastSeverity = null;
logdata.trim().split(/\n/).forEach(line => {
const priorityMatch = line.match(/^<(\w+)>/);
if (!priorityMatch) return;
const tag = priorityMatch[1];
const isCont = tag === 'c';
const cleanLine = line.replace(/^<\w+>/, '');
const timeMatch = cleanLine.match(/^\[\s*(\d+(?:\.\d+)?)\]/);
const time = timeMatch ? parseFloat(timeMatch[1]) : null;
if (!isCont) {
lastSeverity = parseInt(tag, 10); // update severity
}
loglines.push({
severity: isCont ? lastSeverity : parseInt(tag, 10),
isCont,
time,
text: cleanLine
});
});
// Filter by time
const hasStart = this.logFilterFrom;
const hasEnd = this.logFilterTo;
if (hasStart || hasEnd) {
loglines = loglines.filter(({ time }) => {
if (time == null) return false;
let inRange = true;
if (hasStart && hasEnd)
inRange = time >= this.logFilterFrom && time <= this.logFilterTo;
else if (hasStart)
inRange = time >= this.logFilterFrom;
else if (hasEnd)
inRange = time <= this.logFilterTo;
return this.invertLogRangeFilter ? !inRange : inRange;
});
}
// Filter by severity
loglines = loglines.filter(entry => {
if (!entry.isCont) {
if (!this.invertMinSeverity)
return (entry.severity >= this.minSeverity);
else
return (entry.severity < this.minSeverity);
}
});
// Filter by text
if (this.logTextFilter) {
loglines = loglines.filter(({ text }) => {
const match = text.includes(this.logTextFilter);
return this.invertLogTextSearch ? !match : match;
});
}
// Sort by time
if (this.sortLogsDescending) loglines.reverse();
return {
value: loglines.map(l => l.text).join('\n'),
rows: loglines.length + 1
};
}).catch(function(err) {
ui.addNotification(null, E('p', {}, _('Unable to load log data: ' + err.message)));
return '';
});
},
async pollLog() {
const element = document.getElementById('syslog');
if (element) {
const log = await this.retrieveLog();
element.value = log.value;
element.rows = log.rows;
}
},
async load() {
poll.add(this.pollLog.bind(this));
return await this.retrieveLog();
},
render(loglines) {
const scrollDownButton = E('button', {
'id': 'scrollDownButton',
'class': 'cbi-button cbi-button-neutral',
}, _('Scroll to tail', 'scroll to bottom (the tail) of the log file')
);
scrollDownButton.addEventListener('click', () => {
scrollUpButton.scrollIntoView();
scrollDownButton.blur();
});
const scrollUpButton = E('button', {
'id' : 'scrollUpButton',
'class': 'cbi-button cbi-button-neutral',
}, _('Scroll to head', 'scroll to top (the head) of the log file')
);
scrollUpButton.addEventListener('click', () => {
scrollDownButton.scrollIntoView();
scrollUpButton.blur();
});
const self = this;
// Create range invert checkbox
const rangeTimeInvert = E('input', {
'id': 'invertLogRangeTime',
'type': 'checkbox',
'class': 'cbi-input-checkbox',
});
// Create from time filter
const fromTimeFilter = E('input', {
'id': 'logFromTime',
'class': 'cbi-input-text',
'style': 'margin-bottom:10px',
'type': 'number',
'min': '0',
'step': '0.1',
'placeholder': '0.000000',
});
// Create to time filter
const toTimeFilter = E('input', {
'id': 'logToTime',
'class': 'cbi-input-text',
'style': 'margin-bottom:10px',
'type': 'number',
'min': '0',
'step': '0.1',
'placeholder': '0.000000',
});
// Create range invert checkbox
const severityInvert = E('input', {
'id': 'invertSeverity',
'type': 'checkbox',
'class': 'cbi-input-checkbox',
});
// Create severity select-dropdown from severity map
const severitySelect = E('select', {
'id': 'logSeveritySelect',
'class': 'cbi-input-select',
},
this.severity.map(([val, , label]) =>
E('option', { value: val }, label)
));
// Create range invert checkbox
const descendingSort = E('input', {
'id': 'invertAscendingSort',
'type': 'checkbox',
'class': 'cbi-input-checkbox',
});
// Create raw text search invert checkbox
const filterTextInvert = E('input', {
'id': 'invertLogTextSearch',
'type': 'checkbox',
'class': 'cbi-input-checkbox',
});
// Create raw text search text input
const filterTextInput = E('input', {
'id': 'logTextFilter',
'class': 'cbi-input-text',
});
function handleLogFilterChange() {
// time
self.invertLogRangeFilter = rangeTimeInvert.checked;
self.logFilterFrom = fromTimeFilter.value;
self.logFilterTo = toTimeFilter.value;
// severity
self.minSeverity = severitySelect.value;
self.invertMinSeverity = severityInvert.checked;
// sort
self.sortLogsDescending = descendingSort.checked;
// text
self.logTextFilter = filterTextInput.value;
self.invertLogTextSearch = filterTextInvert.checked;
self.pollLog();
}
// time
rangeTimeInvert.addEventListener('change', handleLogFilterChange);
fromTimeFilter.addEventListener('input', handleLogFilterChange);
toTimeFilter.addEventListener('input', handleLogFilterChange);
// severity
severitySelect.addEventListener('change', handleLogFilterChange);
severityInvert.addEventListener('change', handleLogFilterChange);
// sort
descendingSort.addEventListener('change', handleLogFilterChange);
// text
filterTextInput.addEventListener('input', handleLogFilterChange);
filterTextInvert.addEventListener('change', handleLogFilterChange);
return E([], [
E('h2', {}, [ _('Kernel Log') ]),
E('div', { 'id': 'content_syslog' }, [
E('div', { 'style': 'margin-bottom:10px' }, [
E('label', { 'for': 'invertLogFacilitySearch', 'style': 'margin-right:5px' }, _('Not')),
rangeTimeInvert,
E('label', { 'for': 'logFacilitySelect', 'style': 'margin: 0 5px' }, _('between:')),
fromTimeFilter,
E('label', { 'for': 'logSeveritySelect', 'style': 'margin: 0 5px' }, _('and:')),
toTimeFilter,
]),
E('div', { 'style': 'margin-bottom:10px' }, [
E('label', { 'for': 'invertLogSeveritySearch', 'style': 'margin-right:5px' }, _('Not')),
severityInvert,
'\xa0',
severitySelect,
E('label', { 'for': 'logSeveritySelect', 'style': 'margin: 0 5px' }, _('and above')),
]),
E('div', { 'style': 'margin-bottom:10px' }, [
E('label', { 'for': 'invertAscendingSort', 'style': 'margin-right:5px' }, _('Reverse sort')),
descendingSort,
]),
E('div', { 'style': 'margin-bottom:10px' }, [
E('label', { 'for': 'invertLogTextSearch', 'style': 'margin-right:5px' }, _('Not')),
filterTextInvert,
E('label', { 'for': 'logTextFilter', 'style': 'margin: 0 5px' }, _('including:')),
filterTextInput,
]),
E('div', {'style': 'padding-bottom: 20px'}, [scrollDownButton]),
E('textarea', {
'id': 'syslog',
'style': 'font-size:12px',
'readonly': 'readonly',
'wrap': 'off',
'rows': loglines.rows
}, [ loglines.value ]),
E('div', {'style': 'padding-bottom: 20px'}, [scrollUpButton])
])
]);
},
handleSaveApply: null,
handleSave: null,
handleReset: null
});
|