-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview_log.html
477 lines (387 loc) · 18.2 KB
/
view_log.html
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/>
<title>View Log File</title>
<!-- link to JQuery and DataTables javascript libraries -->
<script src="js/jquery-1.11.1.min.js"></script>
<script src="js/jquery.dataTables.min.js"></script>
<script src="js/dataTables.jqueryui.js"></script>
<!-- link to JQuery and DataTables CSS definitions -->
<link rel="stylesheet" href="css/jquery-ui.css"/>
<link rel="stylesheet" href="css/dataTables.jqueryui.css"/>
<!-- define an internal style -->
<style type="text/css">
.right {
float:right;
}
.loading {
color:CornflowerBlue;
}
</style>
<script type="text/javascript">
var websocket_port = "6464";
var view_log_service_name = "/dashboard/log/cloudi.log";
var log_settings_service_name = "/cloudi/api/erlang/logging";
var request_type = "get";
var view_log_web_socket = undefined;
var log_settings_web_socket = undefined;
var websocket_url = "";
var interval_id = undefined;
function is(type, obj) {
if (obj === undefined)
return type === 'undefined';
else if (obj === null)
return type === 'null';
else
return type === Object.prototype.toString.call(obj).slice(8, - 1);
}
String.prototype.startsWith = function (str) {
return this.slice(0, str.length) == str;
};
// This function is the high-level controller for viewing current log settings
function refresh_log() {
// reset the redirect value text
$("#set_redirect_input").val("unknown");
// Get the current log settings
send_log_settings_service();
}
// This function uses a web socket to request the current log file contents
function send_view_log_service() {
// if the web socket is undefined then display an error
if (view_log_web_socket == undefined) {
$('#connectionStatus').text("Not connected");
open_view_log_service();
}
// if the web socket is in an open status then send the request
if (view_log_web_socket.readyState == view_log_web_socket.OPEN) {
var request = "";
view_log_web_socket.send(request);
}
}
// This function opens the web socket used to view the current log file contents
function open_view_log_service() {
if (!("WebSocket" in window)) {
$('#connectionStatus').text("Not connected");
alert("This browser does not support WebSockets");
return;
}
$('#connectionStatus').text("Connecting");
websocket_url = "ws://" + $("#hostname").val() + ":" + websocket_port + view_log_service_name;
view_log_web_socket = new WebSocket(websocket_url);
console.log("Connecting to " + websocket_url);
// define function that is called when the web socket is opened
view_log_web_socket.onopen = function () {
$('#connectionStatus').text("Connected");
console.log("Connected");
send_view_log_service();
};
// define function that is called when an error occurs with the websocket
view_log_web_socket.onerror = function () {
$('#connectionStatus').text("Error");
console.log("Websocket error");
// turn off the timed page refresh
if (interval_id != undefined) {
clearInterval(interval_id);
interval_id = undefined;
}
// hide the loading message
$('#loadingMessage').hide();
alert("Error connecting to websocket " + websocket_url);
};
// define function that is called when data is available on the websocket
handle_message = function (data) {
if (data.startsWith("notification:")) {
// client state check to determine this is an incoming
// service request, not an incoming response
console.log("Request (in): " + data);
var response = "ok";
view_log_web_socket.send(response);
console.log("Response (in): " + response);
}
else {
//console.log("Response (out): " + data);
console.log("Processing response");
if (data != "got connect! yay!") {
// attempt to parse the data response
var start = 0;
var end = 0;
var log_entries = [];
var remaining_data = data;
var loglevel_regexp = new RegExp($("#set_level_input").val());
var date_regexp = /[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T/;
do {
// parse the log date
start = remaining_data.search(date_regexp);
if (start >= 0) {
end = remaining_data.indexOf(" ", start);
var logDate = remaining_data.substring(start, end);
// parse the log level
start = end + 1;
end = remaining_data.indexOf(" ", start);
var logLevel = remaining_data.substring(start, end);
// parse the log source
start = end + 1;
end = remaining_data.indexOf(")", start) + 1;
var logSource = remaining_data.substring(start, end);
// parse the log message
remaining_data = remaining_data.substring(end + 1);
end = remaining_data.search(date_regexp) - 1;
var logMessage = remaining_data.substring(0, end);
// shift the remaining text
remaining_data = remaining_data.substring(end);
// filter by log level
if (loglevel_regexp.test(logLevel)) {
// create a new log entry object with the various data elements
var lineNumber = log_entries.length + 1;
var logEntry = new Object([lineNumber, logDate, logLevel, logSource, logMessage]);
// add the log entry object to the array
log_entries[log_entries.length] = logEntry;
}
}
}
while (start >= 0);
// display the log entries in the table
updateTable(log_entries);
// setup time interval to refresh page
if (interval_id == undefined) {
interval_id = setInterval("refresh_log();", 60000);
}
}
}
};
// define function that is called when a message is received on the web socket
view_log_web_socket.onmessage = function (evt) {
var data = evt.data;
if (is("Blob", data)) {
// for the example, treat binary as text
var reader = new FileReader();
reader.readAsText(data, "text/plain");
reader.onload = function (reader_evt) {
data = reader_evt.target.result;
handle_message(data);
};
}
else {
handle_message(data);
}
};
// define function that is called when the websocket is closed
view_log_web_socket.onclose = function () {
view_log_web_socket = undefined;
$('#connectionStatus').text("Not connected");
console.log("Connection closed");
};
}
// This function closes the web socket used to view the current log file contents
function close_view_log_service() {
$('#connectionStatus').text("Not connected");
if (view_log_web_socket == undefined) {
return;
}
view_log_web_socket.close();
}
// This function uses a web socket to request the current logging settings
function send_log_settings_service() {
// if the web socket is undefined then display an error
if (log_settings_web_socket == undefined) {
$('#connectionStatus').text("Not connected");
open_log_settings_service();
}
// if the web socket is in an open status then send the request
if (log_settings_web_socket.readyState == log_settings_web_socket.OPEN) {
log_settings_web_socket.send(request_type);
}
}
// This function opens the web socket used to get the current logging settings
function open_log_settings_service() {
if (!("WebSocket" in window)) {
$('#connectionStatus').text("Not connected");
alert("This browser does not support WebSockets");
return;
}
$('#connectionStatus').text("Connecting");
websocket_url = "ws://" + $("#hostname").val() + ":" + websocket_port + log_settings_service_name;
log_settings_web_socket = new WebSocket(websocket_url);
console.log("Connecting to " + websocket_url);
// define function that is called when the web socket is opened
log_settings_web_socket.onopen = function () {
$('#connectionStatus').text("Connected");
console.log("Connected");
send_log_settings_service();
};
// define function that is called when an error occurs with the websocket
log_settings_web_socket.onerror = function () {
$('#connectionStatus').text("Error");
console.log("Websocket error");
// turn off the timed page refresh
if (interval_id != undefined) {
clearInterval(interval_id);
interval_id = undefined;
}
// hide the loading message
$('#loadingMessage').hide();
alert("Error connecting to websocket " + websocket_url);
};
// define function that is called when data is available on the websocket
handle_message_log_settings = function (data) {
if (data.startsWith("notification:")) {
// client state check to determine this is an incoming
// service request, not an incoming response
console.log("Request (in): " + data);
var response = "ok";
log_settings_web_socket.send(response);
console.log("Response (in): " + response);
}
else {
//console.log("Response (out): " + data);
console.log("Processing response");
if (data != "got connect! yay!") {
// attempt to parse the data response
var start = 0;
var end = 0;
$("#set_redirect_input").val("undefined");
// parse the redirect setting
searchString = "redirect,";
start = data.indexOf(searchString);
if (start > 0) {
end = data.indexOf("}", start);
redirectValue = data.substring(start + searchString.length, end);
// set the value of the input field
$("#set_redirect_input").val(redirectValue);
// display an alert message if the log file has been redirected
if ($("#set_redirect_input").val() != "undefined") {
alert("The log file has been redirected and can not be displayed");
// hide the loading message
$('#loadingMessage').hide();
close_log_settings_service();
}
}
// Verify that the redirect property is set to "undefined"
if ($("#set_redirect_input").val() == "undefined") {
// Call the dashboard log service to get the current log contents
send_view_log_service();
}
}
}
};
// define function that is called when a message is received on the web socket
log_settings_web_socket.onmessage = function (evt) {
var data = evt.data;
if (is("Blob", data)) {
// for the example, treat binary as text
var reader = new FileReader();
reader.readAsText(data, "text/plain");
reader.onload = function (reader_evt) {
data = reader_evt.target.result;
handle_message_log_settings(data);
};
}
else {
handle_message_log_settings(data);
}
};
// define function that is called when the websocket is closed
log_settings_web_socket.onclose = function () {
log_settings_web_socket = undefined;
$('#connectionStatus').text("Not connected");
console.log("Connection closed");
};
}
// This function closes the web socket used to get the current logging settings
function close_log_settings_service() {
$('#connectionStatus').text("Not connected");
if (log_settings_web_socket == undefined) {
return;
}
log_settings_web_socket.close();
}
</script>
</head>
<body>
<script type="text/javascript">
// This function is called by the server when data is ready to be processed
function updateTable(logEntries) {
// clear table
var oTable = $('#logTable').dataTable();
oTable.fnClearTable();
// process each object in the array
for (i = 0;i < logEntries.length;i++) {
logEntry = logEntries[i];
oTable.fnAddData([logEntry[0], logEntry[1], logEntry[2], logEntry[3], logEntry[4]]);
}
// hide the loading message
$('#loadingMessage').hide();
}
</script>
<div id="logo">
<img class="right" src="powered_by_cloudi.png"></img>
<h1>View Log File</h1>
</div>
<div id="loadingMessage">
<h2 class="loading">Waiting for data...</h2>
</div>
<div>
<input id="hostname" type="text" value="localhost" title="Host name or address to be monitored"></input>
<button class="left" onclick="refresh_log()">Refresh Now</button>
<label>Filter by Level</label>
<select id="set_level_input" onchange="refresh_log()">
<option selected="selected" value="TRACE|DEBUG|INFO|WARN|ERROR|FATAL">≥
Trace</option>
<option value="TRACE">= Trace</option>
<option value="DEBUG|INFO|WARN|ERROR|FATAL">≥ Debug</option>
<option value="DEBUG">= Debug</option>
<option value="INFO|WARN|ERROR|FATAL">≥ Info</option>
<option value="INFO">= Info</option>
<option value="WARN|ERROR|FATAL">≥ Warn</option>
<option value="WARN">= Warn</option>
<option value="ERROR|FATAL">≥ Error</option>
<option value="ERROR">= Error</option>
<option value="FATAL">= Fatal</option>
</select>
<input id="set_redirect_input" type="hidden"></input>
<label class="right" id="connectionStatus"></label>
</div>
<table id="logTable" class="display">
<thead>
<tr>
<th>Line #</th>
<th>Date</th>
<th>Level</th>
<th>Source</th>
<th>Message</th>
</tr>
</thead>
<tbody id="logTableBody"></tbody>
</table>
<script type="text/javascript">
$(document).ready(function () {
// change the table attributes to support jQuery styles
$('#logTable').dataTable( {
"bJQueryUI" : true, "sPaginationType" : "full_numbers", "lengthMenu" : [10, 100, 500, "All"], "pageLength" : 500, "columnDefs" : [
{
"width" : "50px", "targets" : 0
},
{
"width" : "150px", "targets" : 1
},
{
"width" : "50px", "targets" : 2
}
]
});
// clear the table upon first displaying the page
var oTable = $('#logTable').dataTable();
oTable.fnClearTable();
// assign default hostname
$("#hostname").val(location.host);
// show the loading message
$('#loadingMessage').show();
// set the connection status
$('#connectionStatus').text("Not connected");
// call the service request function now
refresh_log();
});
</script>
</body>
</html>