-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviewlog.ejs
More file actions
242 lines (232 loc) · 5.84 KB
/
viewlog.ejs
File metadata and controls
242 lines (232 loc) · 5.84 KB
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
<!DOCTYPE html>
<html lang="ja" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>Server Log Watcher: <%= wsHost %></title>
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<style>
h1 {
font-family: Arial, Helvetica;
}
#logs {
list-style-type: none;
margin: 24px 0px 0px;
padding: 0px;
}
.log {
word-wrap: break-word;
word-break: break-all;
font-family: Osaka-mono, "Osaka-等幅", "MS ゴシック", monospace;
line-height: 1;
margin: 0px 0px;
padding: 1px;
border: 1px solid rgba(255, 255, 255, 0);
border-radius: 4px;
-webkit-transition: all .5s linear;
transition: all .5s linear;
}
.log:hover, .log.odd:hover {
background-color: #ffd;
border: 1px solid #33c;
}
.log.odd {
background-color: #eee;
}
footer {
background: linear-gradient(rgba(255, 255, 255, 0), white);
border: 0 none;
bottom: 0;
height:80px;
left: 0;
position: fixed;
float: left;
width: 100%;
}
#indicator {
position: absolute;
top: 8px;
right: 8px;
min-width: 18px;
height: 18px;
border-radius: 10px;
background-color: #0f0;
padding: 1px;
text-align: center;
font-family: Arial, Helvetica, Sans-selif;
font-weight: bold;
color: white;
}
#indicator.pause {
background-color: red;
border-radius: 0px;
}
.hidden, .odd.hidden {
display: none;
background-color: #ffc;
}
</style>
</head>
<body>
<h1>Server Log Watcher: <%= wsHost %></h1>
<div id="indicator"></div>
<form name="logChooser" onsubmit="return false;">
<label for="logfile">監視ログファイル変更</label>
<select id="logfile" name="logfile"
onchange="logWatch.changeLog();"><%
var i =0;
logList.forEach( function(file) { %>
<option value="<%= i++ %>"><%= file %></option> <% }) %>
</select>
<input type="checkbox" id="cb_pause"
onchange="logWatch.checkbox();"
/><label for="cb_pause">一時停止</label>
</form>
<ul id="logs"></ul>
<footer></footer>
</body>
<script>
// 初期値設定
var logWatch = {
port: <%= wsPort %>,
host: "<%= wsHost %>",
odd : 0,
isPause : false,
hiddenCount: 0,
dom : {
logs : $("#logs"),
logfile : $("#logfile"),
pause : $("#cb_pause"),
indicator: $("#indicator")
}
};
logWatch.url = "ws://" + logWatch.host + ":" + logWatch.port + "/";
// ログの変更関連
logWatch.clear = function() {
this.dom.logs.children().remove();
};
logWatch.changeLog = function() {
ws.send(this.dom.logfile.val());
this.clear ();
};
logWatch.showIndicator = function() {
if ( this.isPause ) {
this.dom.indicator.addClass("pause");
}
else {
this.dom.indicator.removeClass("pause");
}
};
// ログ表示の一時停止・再開関連
// ポーズチェックボックスの確認
logWatch.pauseIsChecked = function() {
return $(this.dom.pause).is(":checked");
};
// ポーズ解除
logWatch.resume = function() {
this.isPause = false;
$(".paused").fadeIn().removeClass("paused").removeClass("hidden");
this.showIndicator();
this.clearHiddenCount();
this.showHiddenCount();
};
// ポーズ
logWatch.pause = function() {
this.isPause = true;
this.showIndicator();
};
// チェックボックス操作によるポーズ・ポーズ解除
logWatch.checkbox = function() {
if ( this.pauseIsChecked() ) {
this.pause();
}
else {
this.resume();
}
};
// マウス操作によるポーズ
logWatch.mouseOver = function() {
this.pause();
};
// マウス操作によるポーズ解除
logWatch.mouseOut = function() {
if (! this.pauseIsChecked() ) {
this.resume();
}
};
// ログの更新関連
// ステージへ追加
logWatch.append = function(data) {
data = data.replace(/[\x00-\x1f\x7f]/g, ""); // 制御コード消去
data = data.replace(/&/g, "&"); // HTML表示用にアンパサンドを文字参照に
data = data.replace(/</g, "<"); // HTML表示用に不等号を文字参照に
data = data.replace(/>/g, ">"); // HTML表示用に不等号を文字参照に
var item = $('<li class="log hidden">' + data + "</li>");
if ( this.odd ) {
item.addClass("odd");
}
if ( this.isPause ) {
item.addClass("paused");
}
var self = this;
item.mouseover( function() { self.mouseOver(); } );
item.mouseout ( function() { self.mouseOut (); } );
this.dom.logs.prepend(item);
if ( !this.isPause ) {
item.fadeIn(60).removeClass("hidden");
} else {
this.incHiddenCount();
this.showHiddenCount();
}
};
// カウント関連
logWatch.incHiddenCount = function() {
this.hiddenCount++;
};
logWatch.getHiddenCount = function() {
return this.hiddenCount;
};
logWatch.clearHiddenCount = function() {
this.hiddenCount = 0;
};
logWatch.showHiddenCount = function() {
var count = this.getHiddenCount();
if ( count == 0 ) {
count = "";
}
this.dom.indicator.text( count );
};
logWatch.addCount = function() {
this.odd = ++this.odd % 2;
};
// WebSocketオブジェクト
var WebSocket = window.WebSocket || window.MozWebSocket;
try {
ws = new WebSocket (logWatch.url);
}
catch (e) {
logWatch.append("接続できませんでした");
console.error(e.toString());
}
// DOM構築後処理(WebSocket関係)
$( function() {
ws.onopen = function() {
logWatch.append( logWatch.url + "へ接続しました");
};
ws.onerror = function(event){
//エラー処理
console.log(event);
};
// データが着信すると動作するonmessageイベント
ws.onmessage = function(msg) {
var data = JSON.parse( msg.data );
logWatch.append( data );
logWatch.addCount();
};
ws.onclose = function() {
logWatch.append("接続が切れました(" + logWatch.url + ")<br />"
+ "サーバ側にnode.jsが設置され、サーバスクリプトが"
+ "動いていることを確認してください。");
};
});
</script>
</html>