-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
156 lines (137 loc) · 5.25 KB
/
index.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
<html>
<head>
<link rel="stylesheet" type="text/css" href="semantic-ui/semantic.min.css">
<script src="https://code.jquery.com/jquery-3.1.1.min.js"
integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
<script src="semantic-ui/semantic.min.js"></script>
<script>
$(function () {
var parsedLog = []
$('.ui.sticky').sticky({
context: '.container',
observeChanges: true
})
$('.dropdown').dropdown({
action: 'activate'
})
$('#open-file').on('click', function (e) {
$('#log-file').trigger('click')
e.preventDefault()
})
$('#log-level').on('change', function (e) {
displayLog(parsedLog)
})
$('#log-search').on('input', function (e) {
displayLog(parsedLog)
})
$('#log-file').on('change', function (e) {
var input = event.target;
parsedLog = []
var reader = new FileReader();
reader.onload = function () {
var text = reader.result.split("\n");
for (let line of text) {
if (line.trim().length == 0) continue
var splitLine = line.split(' ')
var columns = splitLine.slice(0, 3)
// alert(columns)
var text = splitLine.slice(3).join(' ')
parsedLog.push({
level: columns[0].replace(/\[|\]/gi, ''),
date: columns[1].replace(/\[|\]/gi, ''),
method: columns[2].replace(/\[|\]/gi, ''),
message: text
})
}
// document.write(JSON.stringify(parsedLog, null, 2))
displayLog(parsedLog)
};
reader.readAsText(input.files[0]);
})
function displayLog(log) {
if (log.length == 0) return
var level = $('#log-level').val()
var search = $('#log-search').val()
var filteredLog = log.filter(line => {
var included = true
if (search.length > 0)
included = included && line.message.toLowerCase().includes(search.toLowerCase())
if (level != "ALL")
included = included && line.level == level
return included
})
var table = $("#log-table").find('tbody')
table.empty()
for (let line of filteredLog) {
var row = $('<tr>');
row.append($('<td>').text(line.level))
row.append($('<td>').text(line.date))
row.append($('<td>').text(line.message))
row.append($('<td>').text(line.method).addClass('right aligned'))
switch (line.level.toLowerCase()) {
case "error":
case "fatal":
row.addClass("error")
break;
case "info":
break;
case "warn":
row.addClass("warning")
break;
}
table.append(row)
}
$('.ui.sticky').sticky('refresh')
}
})
</script>
<style>
.no-border {
border: none !important;
}
</style>
</head>
<body>
<div class="container fluid">
<div class="ui menu stackable sticky attached">
<div class="header item">
Paperback - Log Reader
</div>
<a class="item" id="open-file">
Open File
</a>
<div class="right menu">
<select class="ui dropdown item no-border" id="log-level">
<option>ALL</option>
<option>INFO</option>
<option>ERROR</option>
<option>WARN</option>
<option>FATAL</option>
</select>
<div class="item">
<div class="ui transparent icon input">
<input class="prompt" type="text" placeholder="Search" id="log-search">
<i class="search link icon"></i>
</div>
</div>
</div>
</div>
<table class="ui selectable table attached compact" id="log-table">
<thead>
<tr>
<th>Level</th>
<th>Date</th>
<th class="sixteen wide">Message</th>
<th>Method</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="4">No File Opened</td>
</tr>
</tbody>
</table>
<input type="file" id="log-file" hidden="true">
</div>
</body>
</html>