mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 15:10:55 +00:00
Merge pull request #4004 from gokangaroo/develop
avoid `panic: send on closed channel` after closing logger.
This commit is contained in:
commit
0dab959c95
@ -16,6 +16,7 @@ package logs
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Try each log level in decreasing order of priority.
|
// Try each log level in decreasing order of priority.
|
||||||
@ -49,3 +50,15 @@ func TestConsoleNoColor(t *testing.T) {
|
|||||||
log.SetLogger("console", `{"color":false}`)
|
log.SetLogger("console", `{"color":false}`)
|
||||||
testConsoleCalls(log)
|
testConsoleCalls(log)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test console async
|
||||||
|
func TestConsoleAsync(t *testing.T) {
|
||||||
|
log := NewLogger(100)
|
||||||
|
log.SetLogger("console")
|
||||||
|
log.Async()
|
||||||
|
//log.Close()
|
||||||
|
testConsoleCalls(log)
|
||||||
|
for len(log.msgChan) != 0 {
|
||||||
|
time.Sleep(1 * time.Millisecond)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -295,7 +295,11 @@ func (bl *BeeLogger) writeMsg(logLevel int, msg string, v ...interface{}) error
|
|||||||
lm.level = logLevel
|
lm.level = logLevel
|
||||||
lm.msg = msg
|
lm.msg = msg
|
||||||
lm.when = when
|
lm.when = when
|
||||||
bl.msgChan <- lm
|
if bl.outputs != nil {
|
||||||
|
bl.msgChan <- lm
|
||||||
|
} else {
|
||||||
|
logMsgPool.Put(lm)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
bl.writeToLoggers(when, msg, logLevel)
|
bl.writeToLoggers(when, msg, logLevel)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user