1
0
mirror of https://github.com/astaxie/beego.git synced 2024-06-03 04:33:28 +00:00

Merge pull request #4004 from gokangaroo/develop

avoid `panic: send on closed channel` after closing logger.
This commit is contained in:
Ming Deng 2020-06-06 13:09:36 +08:00 committed by GitHub
commit 0dab959c95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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)
} }