Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
ecab3970
Commit
ecab3970
authored
Jan 28, 2016
by
youngsterxyf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
try to fix the little bug when calling Close or Flush in async mode
parent
85c0fcd3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
17 deletions
+31
-17
log.go
logs/log.go
+31
-17
No files found.
logs/log.go
View file @
ecab3970
...
...
@@ -98,6 +98,8 @@ type BeeLogger struct {
loggerFuncCallDepth
int
asynchronous
bool
msgChan
chan
*
logMsg
signalChan
chan
string
wg
sync
.
WaitGroup
outputs
[]
*
nameLogger
}
...
...
@@ -122,6 +124,8 @@ func NewLogger(channelLen int64) *BeeLogger {
bl
.
level
=
LevelDebug
bl
.
loggerFuncCallDepth
=
2
bl
.
msgChan
=
make
(
chan
*
logMsg
,
channelLen
)
bl
.
signalChan
=
make
(
chan
string
,
1
)
bl
.
wg
.
Add
(
1
)
return
bl
}
...
...
@@ -237,6 +241,27 @@ func (bl *BeeLogger) startLogger() {
case
bm
:=
<-
bl
.
msgChan
:
bl
.
writeToLoggers
(
bm
.
when
,
bm
.
msg
,
bm
.
level
)
logMsgPool
.
Put
(
bm
)
case
sg
:=
<-
bl
.
signalChan
:
// Now should only send "flush" or "close" to bl.signalChan
for
{
if
len
(
bl
.
msgChan
)
>
0
{
bm
:=
<-
bl
.
msgChan
bl
.
writeToLoggers
(
bm
.
when
,
bm
.
msg
,
bm
.
level
)
logMsgPool
.
Put
(
bm
)
continue
}
break
}
for
_
,
l
:=
range
bl
.
outputs
{
l
.
Flush
()
}
if
sg
==
"close"
{
for
_
,
l
:=
range
bl
.
outputs
{
l
.
Destroy
()
}
bl
.
outputs
=
nil
}
bl
.
wg
.
Done
()
}
}
}
...
...
@@ -345,27 +370,16 @@ func (bl *BeeLogger) Trace(format string, v ...interface{}) {
// Flush flush all chan data.
func
(
bl
*
BeeLogger
)
Flush
()
{
for
_
,
l
:=
range
bl
.
outputs
{
l
.
Flush
()
}
bl
.
signalChan
<-
"flush"
bl
.
wg
.
Wait
()
bl
.
wg
.
Add
(
1
)
}
// Close close logger, flush all chan data and destroy all adapters in BeeLogger.
func
(
bl
*
BeeLogger
)
Close
()
{
for
{
if
len
(
bl
.
msgChan
)
>
0
{
bm
:=
<-
bl
.
msgChan
bl
.
writeToLoggers
(
bm
.
when
,
bm
.
msg
,
bm
.
level
)
logMsgPool
.
Put
(
bm
)
continue
}
break
}
for
_
,
l
:=
range
bl
.
outputs
{
l
.
Flush
()
l
.
Destroy
()
}
bl
.
outputs
=
nil
bl
.
signalChan
<-
"close"
bl
.
wg
.
Wait
()
bl
.
wg
.
Add
(
1
)
}
func
formatLogTime
(
when
time
.
Time
)
string
{
...
...
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