fix 5079: only log msg when the channel is not closed (#5132)
This commit is contained in:
parent
1d165675f4
commit
2d2e11d57d
@ -3,6 +3,7 @@
|
|||||||
- [add read through for cache module](https://github.com/beego/beego/pull/5116)
|
- [add read through for cache module](https://github.com/beego/beego/pull/5116)
|
||||||
- [add singleflight cache for cache module](https://github.com/beego/beego/pull/5119)
|
- [add singleflight cache for cache module](https://github.com/beego/beego/pull/5119)
|
||||||
- [Fix 5129: must set formatter after init the logger](https://github.com/beego/beego/pull/5130)
|
- [Fix 5129: must set formatter after init the logger](https://github.com/beego/beego/pull/5130)
|
||||||
|
- [Fix 5079: only log msg when the channel is not closed](https://github.com/beego/beego/pull/5132)
|
||||||
|
|
||||||
# v2.0.7
|
# v2.0.7
|
||||||
- [Upgrade github.com/go-kit/kit, CVE-2022-24450](https://github.com/beego/beego/pull/5121)
|
- [Upgrade github.com/go-kit/kit, CVE-2022-24450](https://github.com/beego/beego/pull/5121)
|
||||||
|
|||||||
@ -225,7 +225,7 @@ func (bl *BeeLogger) SetLogger(adapterName string, configs ...string) error {
|
|||||||
func (bl *BeeLogger) DelLogger(adapterName string) error {
|
func (bl *BeeLogger) DelLogger(adapterName string) error {
|
||||||
bl.lock.Lock()
|
bl.lock.Lock()
|
||||||
defer bl.lock.Unlock()
|
defer bl.lock.Unlock()
|
||||||
outputs := []*nameLogger{}
|
outputs := make([]*nameLogger, 0, len(bl.outputs))
|
||||||
for _, lg := range bl.outputs {
|
for _, lg := range bl.outputs {
|
||||||
if lg.name == adapterName {
|
if lg.name == adapterName {
|
||||||
lg.Destroy()
|
lg.Destroy()
|
||||||
@ -360,9 +360,13 @@ func (bl *BeeLogger) startLogger() {
|
|||||||
gameOver := false
|
gameOver := false
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case bm := <-bl.msgChan:
|
case bm, ok := <-bl.msgChan:
|
||||||
bl.writeToLoggers(bm)
|
// this is a terrible design to have a signal channel that accept two inputs
|
||||||
logMsgPool.Put(bm)
|
// so we only handle the msg if the channel is not closed
|
||||||
|
if ok {
|
||||||
|
bl.writeToLoggers(bm)
|
||||||
|
logMsgPool.Put(bm)
|
||||||
|
}
|
||||||
case sg := <-bl.signalChan:
|
case sg := <-bl.signalChan:
|
||||||
// Now should only send "flush" or "close" to bl.signalChan
|
// Now should only send "flush" or "close" to bl.signalChan
|
||||||
bl.flush()
|
bl.flush()
|
||||||
@ -603,7 +607,10 @@ func (bl *BeeLogger) flush() {
|
|||||||
if bl.asynchronous {
|
if bl.asynchronous {
|
||||||
for {
|
for {
|
||||||
if len(bl.msgChan) > 0 {
|
if len(bl.msgChan) > 0 {
|
||||||
bm := <-bl.msgChan
|
bm, ok := <-bl.msgChan
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
bl.writeToLoggers(bm)
|
bl.writeToLoggers(bm)
|
||||||
logMsgPool.Put(bm)
|
logMsgPool.Put(bm)
|
||||||
continue
|
continue
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user