Commit 5d5e084e by lichenggang

version1.0.0

- 支持多客户端多文件同时查看
- 支持短线重连
- 支持即时查看
parent bb08e140
......@@ -26,22 +26,8 @@ func monitor(filePath string) {
}
break
}
offset := fileInfo.Size()
//初始监听时加载全部内容
allcontent_msg := make([]byte, offset)
allcontent_file, err := os.Open(filePath)
if err != nil {
log.Printf("[seelog] error:%v", err.Error())
}
_, err = allcontent_file.Read(allcontent_msg)
if err != nil {
log.Printf("[seelog] error:%v", err.Error())
}
all_content := filename + "$$" + string(allcontent_msg)
manager.broadcast <- []byte(all_content)
allcontent_file.Close()
offset := fileInfo.Size()
for {
fileInfo, err = os.Stat(filePath)
if err != nil {
......
......@@ -106,6 +106,22 @@ func gen(directory string, file_map map[string]map[client]bool) func(ws *websock
fmt.Printf("Add a new monitored file [%s]\n", filename)
}
//初始监听时加载全部内容
file_path := directory + filename
fileInfo, err := os.Stat(file_path)
allcontent_file, err := os.Open(file_path)
offset := fileInfo.Size()
allcontent_msg := make([]byte, offset)
if err != nil {
log.Printf("[seelog] error:%v", err.Error())
}
_, err = allcontent_file.Read(allcontent_msg)
if err != nil {
log.Printf("[seelog] error:%v", err.Error())
}
all_content := filename + "$$" + string(allcontent_msg)
manager.broadcast <- []byte(all_content)
allcontent_file.Close()
manager.register <- cli
go cli.read()
......
......@@ -14,11 +14,21 @@
var filterText = ""
function connect (){
var ws = new WebSocket("ws://"+ window.location.host +"/ws?file={{ . }}");
ws.onmessage = function(e) {
console.log(filterText)
if (out && (filterText == "" || e.data.indexOf(filterText) != -1)){
$('#log').append("<pre style='color: white;font-size: 15px'>"+ e.data +"</pre>").scrollTop($('#log')[0].scrollHeight)
snsArr=e.data.split(/[(\r\n)\r\n]+/);
snsArr.forEach((item,index)=>{
if(!item){
snsArr.splice(index,1);//删除空项
}
})
snsArr.forEach((item, index)=>{
$('#log').append("<pre style='color: white;font-size: 15px;margin: 3px'>"+ item +"</pre>").scrollTop($('#log')[0].scrollHeight)
})
}
};
ws.onclose = function () {
......@@ -27,6 +37,7 @@
}
ws.onopen = function () {
$('#status').css("background-color","chartreuse").text("连接成功")
$('#clear').click()
}
ws.onerror = function (e) {
$('#status').css("background-color","red").text("链接断开")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment