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
58ec53d6
authored
May 17, 2022
by
刘豪
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
修复退出协程未删除映射的bug
parent
1fc283e0
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
3 additions
and
2 deletions
code/application.go
code/monitor.go
code/application.go
View file @
58ec53d6
...
@@ -87,7 +87,7 @@ func getCtxHand(fileMap map[string]map[Client]bool) func(ctx iris.Context) {
...
@@ -87,7 +87,7 @@ func getCtxHand(fileMap map[string]map[Client]bool) func(ctx iris.Context) {
utils
.
Log
.
Infof
(
"%s has been monitored"
,
filePath
)
utils
.
Log
.
Infof
(
"%s has been monitored"
,
filePath
)
}
else
{
}
else
{
// 监控文件
// 监控文件
go
monitor
(
file
Path
,
cli
)
go
monitor
(
file
Map
,
filePath
)
l
:=
make
(
map
[
Client
]
bool
)
l
:=
make
(
map
[
Client
]
bool
)
l
[
*
cli
]
=
true
l
[
*
cli
]
=
true
fileMap
[
filePath
]
=
l
fileMap
[
filePath
]
=
l
...
...
code/monitor.go
View file @
58ec53d6
...
@@ -7,7 +7,7 @@ import (
...
@@ -7,7 +7,7 @@ import (
)
)
// 监控日志文件
// 监控日志文件
func
monitor
(
file
Path
string
,
cli
*
Client
)
{
func
monitor
(
file
Map
map
[
string
]
map
[
Client
]
bool
,
filePath
string
)
{
defer
func
()
{
defer
func
()
{
if
err
:=
recover
();
err
!=
nil
{
if
err
:=
recover
();
err
!=
nil
{
utils
.
Log
.
Errorf
(
"defer [seelog] error:%+v"
,
err
)
utils
.
Log
.
Errorf
(
"defer [seelog] error:%+v"
,
err
)
...
@@ -62,6 +62,7 @@ func monitor(filePath string, cli *Client) {
...
@@ -62,6 +62,7 @@ func monitor(filePath string, cli *Client) {
// 防止协程开启太多
// 防止协程开启太多
if
startMonitorTime
<
(
time
.
Now
()
.
Unix
()
-
3600
)
{
if
startMonitorTime
<
(
time
.
Now
()
.
Unix
()
-
3600
)
{
utils
.
Log
.
Info
(
"超过1小时限制时间,退出协程"
)
utils
.
Log
.
Info
(
"超过1小时限制时间,退出协程"
)
delete
(
fileMap
,
filePath
)
return
return
}
else
{
}
else
{
time
.
Sleep
(
500
*
time
.
Millisecond
)
time
.
Sleep
(
500
*
time
.
Millisecond
)
...
...
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