-
Notifications
You must be signed in to change notification settings - Fork 0
/
LogSearch.js
executable file
·69 lines (53 loc) · 1.37 KB
/
LogSearch.js
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
function LogSearch (arg) {
// private fields
var log_file = arg['logFile'];
var list = false;
var cache = new Array(); // strings already searched
// public method
this.search = search;
_initialize();
function search(str) {
if (str == '') return '';
if (cache[str]) return cache[str];
var result = new Array();
var regexp = new RegExp(_quoteMetaChar(str), 'i');
for (var i = 0; i < list.length; i++) {
var cols = list[i].split('\s');
if (regexp.exec(cols[0])) {
result.push(list[i]);
}
}
cache[str] = result;
return result;
}
function _quoteMetaChar(str) {
return str.replace(/(\W)/, '\\$1');
}
function _initialize() {
var xmlHttpRequest = _createXmlHttpObject();
xmlHttpRequest.open('GET', log_file, true);
xmlHttpRequest.onreadystatechange = function() {
if (xmlHttpRequest.readyState == 4) {
var text = xmlHttpRequest.responseText;
list = text.split("\n");
}
}
xmlHttpRequest.send(null);
}
function _createXmlHttpObject() {
var xmlHttpRequest = false;
try {
xmlHttpRequest = new ActiveXObject('Msxml2.XMLHTTP');
} catch (e) {
try {
xmlHttpRequest = new ActiveXObject('Microsoft.XMLHTTP');
} catch (E) {
xmlHttpRequest = false;
}
}
if (!xmlHttpRequest && typeof XMLHttpRequest != 'undefined') {
xmlHttpRequest = new XMLHttpRequest();
}
return xmlHttpRequest;
}
}