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
69804afc
Commit
69804afc
authored
Jan 12, 2016
by
JessonChan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use pool to logMsg
parent
164366ae
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
7 deletions
+16
-7
log.go
logs/log.go
+16
-7
No files found.
logs/log.go
View file @
69804afc
...
...
@@ -95,7 +95,7 @@ type BeeLogger struct {
enableFuncCallDepth
bool
loggerFuncCallDepth
int
asynchronous
bool
msg
chan
*
logMsg
msg
Chan
chan
*
logMsg
outputs
[]
*
nameLogger
}
...
...
@@ -109,6 +109,8 @@ type logMsg struct {
msg
string
}
var
logMsgPool
*
sync
.
Pool
// NewLogger returns a new BeeLogger.
// channelLen means the number of messages in chan(used where asynchronous is true).
// if the buffering chan is full, logger adapters write to file or other way.
...
...
@@ -116,13 +118,18 @@ func NewLogger(channelLen int64) *BeeLogger {
bl
:=
new
(
BeeLogger
)
bl
.
level
=
LevelDebug
bl
.
loggerFuncCallDepth
=
2
bl
.
msg
=
make
(
chan
*
logMsg
,
channelLen
)
bl
.
msg
Chan
=
make
(
chan
*
logMsg
,
channelLen
)
return
bl
}
// Async set the log to asynchronous and start the goroutine
func
(
bl
*
BeeLogger
)
Async
()
*
BeeLogger
{
bl
.
asynchronous
=
true
logMsgPool
=
&
sync
.
Pool
{
New
:
func
()
interface
{}
{
return
&
logMsg
{}
},
}
go
bl
.
startLogger
()
return
bl
}
...
...
@@ -187,10 +194,10 @@ func (bl *BeeLogger) writeMsg(logLevel int, msg string) error {
msg
=
msg
}
if
bl
.
asynchronous
{
lm
:=
new
(
logMsg
)
lm
:=
logMsgPool
.
Get
()
.
(
*
logMsg
)
lm
.
level
=
logLevel
lm
.
msg
=
msg
bl
.
msg
<-
lm
bl
.
msg
Chan
<-
lm
}
else
{
bl
.
writeToLoggers
(
msg
,
logLevel
)
}
...
...
@@ -224,8 +231,9 @@ func (bl *BeeLogger) EnableFuncCallDepth(b bool) {
func
(
bl
*
BeeLogger
)
startLogger
()
{
for
{
select
{
case
bm
:=
<-
bl
.
msg
:
case
bm
:=
<-
bl
.
msg
Chan
:
bl
.
writeToLoggers
(
bm
.
msg
,
bm
.
level
)
logMsgPool
.
Put
(
bm
)
}
}
}
...
...
@@ -342,9 +350,10 @@ func (bl *BeeLogger) Flush() {
// Close close logger, flush all chan data and destroy all adapters in BeeLogger.
func
(
bl
*
BeeLogger
)
Close
()
{
for
{
if
len
(
bl
.
msg
)
>
0
{
bm
:=
<-
bl
.
msg
if
len
(
bl
.
msg
Chan
)
>
0
{
bm
:=
<-
bl
.
msg
Chan
bl
.
writeToLoggers
(
bm
.
msg
,
bm
.
level
)
logMsgPool
.
Put
(
bm
)
continue
}
break
...
...
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