Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
lichenggang
/
web_log
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
5d5e084e
authored
Dec 22, 2020
by
lichenggang
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
version1.0.0
- 支持多客户端多文件同时查看 - 支持短线重连 - 支持即时查看
parent
bb08e140
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
16 deletions
src/code/monitor.go
src/code/server.go
src/templates/page.html
src/code/monitor.go
View file @
5d5e084e
...
@@ -26,22 +26,8 @@ func monitor(filePath string) {
...
@@ -26,22 +26,8 @@ func monitor(filePath string) {
}
}
break
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
{
for
{
fileInfo
,
err
=
os
.
Stat
(
filePath
)
fileInfo
,
err
=
os
.
Stat
(
filePath
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
src/code/server.go
View file @
5d5e084e
...
@@ -106,6 +106,22 @@ func gen(directory string, file_map map[string]map[client]bool) func(ws *websock
...
@@ -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
)
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
manager
.
register
<-
cli
go
cli
.
read
()
go
cli
.
read
()
...
...
src/templates/page.html
View file @
5d5e084e
...
@@ -14,11 +14,21 @@
...
@@ -14,11 +14,21 @@
var
filterText
=
""
var
filterText
=
""
function
connect
(){
function
connect
(){
var
ws
=
new
WebSocket
(
"ws://"
+
window
.
location
.
host
+
"/ws?file={{ . }}"
);
var
ws
=
new
WebSocket
(
"ws://"
+
window
.
location
.
host
+
"/ws?file={{ . }}"
);
ws
.
onmessage
=
function
(
e
)
{
ws
.
onmessage
=
function
(
e
)
{
console
.
log
(
filterText
)
console
.
log
(
filterText
)
if
(
out
&&
(
filterText
==
""
||
e
.
data
.
indexOf
(
filterText
)
!=
-
1
)){
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
()
{
ws
.
onclose
=
function
()
{
...
@@ -27,6 +37,7 @@
...
@@ -27,6 +37,7 @@
}
}
ws
.
onopen
=
function
()
{
ws
.
onopen
=
function
()
{
$
(
'#status'
).
css
(
"background-color"
,
"chartreuse"
).
text
(
"连接成功"
)
$
(
'#status'
).
css
(
"background-color"
,
"chartreuse"
).
text
(
"连接成功"
)
$
(
'#clear'
).
click
()
}
}
ws
.
onerror
=
function
(
e
)
{
ws
.
onerror
=
function
(
e
)
{
$
(
'#status'
).
css
(
"background-color"
,
"red"
).
text
(
"链接断开"
)
$
(
'#status'
).
css
(
"background-color"
,
"red"
).
text
(
"链接断开"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment