1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 13:10:54 +00:00

avoid panic: send on closed channel after closing logger.

This commit is contained in:
huija 2020-06-04 14:52:54 +08:00
parent db2a1134ce
commit b879a07b3a
2 changed files with 18 additions and 1 deletions

View File

@ -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)
}
}

View File

@ -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)
} }