5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
6 <style type="text/css">
7 div#divlogs, div#diventry {
8 font-family: monospace;
10 background-color: #ffffff;
13 border-radius: 10px 10px 10px 10px;
14 border: 1px solid threedshadow;
25 background-color: #ededed;
32 border-right: 1px dotted lightgrey;
36 border-right: 1px dotted lightgrey;
43 td.message > a:link, td.message > a:visited {
44 text-decoration: none;
52 td.message-error > a:link, td.message-error > a:visited {
53 text-decoration: none;
56 td.message-highlight {
60 td.message-highlight > a:link, td.message-highlight > a:visited {
61 text-decoration: none;
64 td > a:hover, td > a:active {
65 text-decoration: underline;
68 table#tablelogs, table#tableentry {
69 border-collapse: collapse;
73 border-right: 1px dotted lightgrey;
110 - show red lines for reboots -->
115 <div id="virtualization"></div>
116 <div id="cutoff"></div>
117 <div id="machine"></div>
118 <div id="usage"></div>
119 <div id="showing"></div>
122 <select id="filter" onchange="onFilterChange(this);" onfocus="onFilterFocus(this);">
123 <option>No filter</option>
125
126 <input id="boot" type="checkbox" onchange="onBootChange(this);">Only current boot</input>
129 <div id="divlogs"><table id="tablelogs"></table></div>
131 <div id="diventry"><table id="tableentry"></table></div>
134 <button id="head" onclick="entriesLoadHead();" title="First Page">⇤</button>
135 <button id="previous" type="button" onclick="entriesLoadPrevious();" title="Previous Page"/>←</button>
136 <button id="next" type="button" onclick="entriesLoadNext();" title="Next Page"/>→</button>
137 <button id="tail" type="button" onclick="entriesLoadTail();" title="Last Page"/>⇥</button>
138
139 <button id="more" type="button" onclick="entriesMore();" title="More Entries"/>+</button>
140 <button id="less" type="button" onclick="entriesLess();" title="Fewer Entries"/>-</button>
144 <span class="key">g</span>: First Page
145 <span class="key">←, k, BACKSPACE</span>: Previous Page
146 <span class="key">→, j, SPACE</span>: Next Page
147 <span class="key">G</span>: Last Page
148 <span class="key">+</span>: More entries
149 <span class="key">-</span>: Fewer entries
152 <script type="text/javascript">
153 var first_cursor = null;
154 var last_cursor = null;
156 function getNEntries() {
158 n = localStorage["n_entries"];
169 function showNEntries(n) {
170 var showing = document.getElementById("showing");
171 showing.innerHTML = "Showing <b>" + n.toString() + "</b> entries.";
174 function setNEntries(n) {
179 localStorage["n_entries"] = n.toString();
183 function machineLoad() {
184 var request = new XMLHttpRequest();
185 request.open("GET", "/machine");
186 request.onreadystatechange = machineOnResult;
187 request.setRequestHeader("Accept", "application/json");
191 function formatBytes(u) {
192 if (u >= 1024*1024*1024*1024)
193 return (u/1024/1024/1024/1024).toFixed(1) + " TiB";
194 else if (u >= 1024*1024*1024)
195 return (u/1024/1024/1024).toFixed(1) + " GiB";
196 else if (u >= 1024*1024)
197 return (u/1024/1024).toFixed(1) + " MiB";
199 return (u/1024).toFixed(1) + " KiB";
201 return u.toString() + " B";
204 function escapeHTML(s) {
205 return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
208 function machineOnResult(event) {
209 if ((event.currentTarget.readyState != 4) ||
210 (event.currentTarget.status != 200 && event.currentTarget.status != 0))
213 var d = JSON.parse(event.currentTarget.responseText);
215 var title = document.getElementById("title");
216 title.innerHTML = 'Journal of ' + escapeHTML(d.hostname);
217 document.title = 'Journal of ' + escapeHTML(d.hostname);
219 var machine = document.getElementById("machine");
220 machine.innerHTML = 'Machine ID is <b>' + d.machine_id + '</b>, current boot ID is <b>' + d.boot_id + '</b>.';
222 var cutoff = document.getElementById("cutoff");
223 var from = new Date(parseInt(d.cutoff_from_realtime) / 1000);
224 var to = new Date(parseInt(d.cutoff_to_realtime) / 1000);
225 cutoff.innerHTML = 'Journal begins at <b>' + from.toLocaleString() + '</b> and ends at <b>' + to.toLocaleString() + '</b>.';
227 var usage = document.getElementById("usage");
228 usage.innerHTML = 'Disk usage is <b>' + formatBytes(parseInt(d.usage)) + '</b>.';
230 var os = document.getElementById("os");
231 os.innerHTML = 'Operating system is <b>' + escapeHTML(d.os_pretty_name) + '</b>.';
233 var virtualization = document.getElementById("virtualization");
234 virtualization.innerHTML = d.virtualization == "bare" ? "Running on <b>bare metal</b>." : "Running on virtualization <b>" + escapeHTML(d.virtualization) + "</b>.";
237 function entriesLoad(range) {
240 range = localStorage["cursor"] + ":0";
244 var url = "/entries";
246 if (localStorage["filter"] != "" && localStorage["filter"] != null) {
247 url += "?_SYSTEMD_UNIT=" + escape(localStorage["filter"]);
249 if (localStorage["boot"] == "1")
252 if (localStorage["boot"] == "1")
256 var request = new XMLHttpRequest();
257 request.open("GET", url);
258 request.onreadystatechange = entriesOnResult;
259 request.setRequestHeader("Accept", "application/json");
260 request.setRequestHeader("Range", "entries=" + range + ":" + getNEntries().toString());
264 function entriesLoadNext() {
265 if (last_cursor == null)
268 entriesLoad(last_cursor + ":1");
271 function entriesLoadPrevious() {
272 if (first_cursor == null)
275 entriesLoad(first_cursor + ":-" + getNEntries().toString());
278 function entriesLoadHead() {
282 function entriesLoadTail() {
283 entriesLoad(":-" + getNEntries().toString());
286 function entriesOnResult(event) {
288 if ((event.currentTarget.readyState != 4) ||
289 (event.currentTarget.status != 200 && event.currentTarget.status != 0))
292 var logs = document.getElementById("tablelogs");
297 var i, l = event.currentTarget.responseText.split('\n');
300 logs.innerHTML = '<tbody><tr><td colspan="3"><i>No further entries...</i></td></tr></tbody>';
311 var d = JSON.parse(l[i]);
312 if (d.MESSAGE == undefined || d.__CURSOR == undefined)
320 if (d.PRIORITY != undefined)
321 priority = parseInt(d.PRIORITY);
326 clazz = "message-error";
327 else if (priority <= 5)
328 clazz = "message-highlight";
332 buf += '<tr><td class="timestamp">';
334 if (d.__REALTIME_TIMESTAMP != undefined) {
335 var timestamp = new Date(parseInt(d.__REALTIME_TIMESTAMP) / 1000);
336 buf += timestamp.toLocaleString();
339 buf += '</td><td class="process">';
341 if (d.SYSLOG_IDENTIFIER != undefined)
342 buf += escapeHTML(d.SYSLOG_IDENTIFIER);
343 else if (d._COMM != undefined)
344 buf += escapeHTML(d._COMM);
346 if (d._PID != undefined)
347 buf += "[" + escapeHTML(d._PID) + "]";
348 else if (d.SYSLOG_PID != undefined)
349 buf += "[" + escapeHTML(d.SYSLOG_PID) + "]";
351 buf += '</td><td class="' + clazz + '"><a href="#entry" onclick="onMessageClick(\'' + d.__CURSOR + '\');">';
353 if (d.MESSAGE == null)
354 buf += "[blob data]";
355 else if (d.MESSAGE instanceof Array)
356 buf += "[" + formatBytes(d.MESSAGE.length) + " blob data]";
358 buf += escapeHTML(d.MESSAGE);
360 buf += '</a></td></tr>';
363 logs.innerHTML = '<tbody>' + buf + '</tbody>';
367 localStorage["cursor"] = fc;
373 function entriesMore() {
374 setNEntries(getNEntries() + 10);
375 entriesLoad(first_cursor);
378 function entriesLess() {
379 setNEntries(getNEntries() - 10);
380 entriesLoad(first_cursor);
383 function onResultMessageClick(event) {
384 if ((event.currentTarget.readyState != 4) ||
385 (event.currentTarget.status != 200 && event.currentTarget.status != 0))
388 var d = JSON.parse(event.currentTarget.responseText);
390 document.getElementById("diventry").style.display = "block";
391 entry = document.getElementById("tableentry");
398 data = "[blob data]";
399 else if (data instanceof Array)
400 data = "[" + formatBytes(data.length) + " blob data]";
402 data = escapeHTML(data);
404 buf += '<tr><td class="field">' + key + '</td><td class="data">' + data + '</td></tr>';
406 entry.innerHTML = '<tbody>' + buf + '</tbody>';
409 function onMessageClick(t) {
410 var request = new XMLHttpRequest();
411 request.open("GET", "/entries?discrete");
412 request.onreadystatechange = onResultMessageClick;
413 request.setRequestHeader("Accept", "application/json");
414 request.setRequestHeader("Range", "entries=" + t + ":0:1");
418 function onKeyUp(event) {
419 switch (event.keyCode) {
423 entriesLoadPrevious();
446 function onMouseWheel(event) {
447 if (event.detail < 0 || event.wheelDelta > 0)
448 entriesLoadPrevious();
453 function onResultFilterFocus(event) {
454 if ((event.currentTarget.readyState != 4) ||
455 (event.currentTarget.status != 200 && event.currentTarget.status != 0))
458 f = document.getElementById("filter");
460 var l = event.currentTarget.responseText.split('\n');
461 var buf = '<option>No filter</option>';
469 var d = JSON.parse(l[i]);
470 if (d._SYSTEMD_UNIT == undefined)
473 buf += '<option value="' + escape(d._SYSTEMD_UNIT) + '">' + escapeHTML(d._SYSTEMD_UNIT) + '</option>';
475 if (d._SYSTEMD_UNIT == localStorage["filter"])
480 if (localStorage["filter"] != null && localStorage["filter"] != "") {
481 buf += '<option value="' + escape(localStorage["filter"]) + '">' + escapeHTML(localStorage["filter"]) + '</option>';
491 function onFilterFocus(w) {
492 var request = new XMLHttpRequest();
493 request.open("GET", "/fields/_SYSTEMD_UNIT");
494 request.onreadystatechange = onResultFilterFocus;
495 request.setRequestHeader("Accept", "application/json");
499 function onFilterChange(w) {
500 if (w.selectedIndex <= 0)
501 localStorage["filter"] = "";
503 localStorage["filter"] = unescape(w.options[w.selectedIndex].value);
508 function onBootChange(w) {
509 localStorage["boot"] = w.checked ? "1" : "0";
513 function initFilter() {
514 f = document.getElementById("filter");
516 var buf = '<option>No filter</option>';
518 var filter = localStorage["filter"];
519 if (filter != null && filter != "") {
520 buf += '<option value="' + escape(filter) + '">' + escapeHTML(filter) + '</option>';
529 function installHandlers() {
530 document.onkeyup = onKeyUp;
532 logs = document.getElementById("divlogs");
533 logs.addEventListener("mousewheel", onMouseWheel, false);
534 logs.addEventListener("DOMMouseScroll", onMouseWheel, false);
539 showNEntries(getNEntries());