Improve logger Pause handling (#24946)
The old EventWriter's Run does: ```go for { handlePause() select { case event <- Queue: write the log event ... } } ``` So, if an event writer is started before the logger is paused, there is a chance that the logger isn't paused for the first message. The new logic is: ```go for { select { case event <- Queue: handlePause() write the log event ... } } ``` Then the event writer can be correctly paused
This commit is contained in:
parent
7314726bab
commit
0d54395fb5
|
@ -68,18 +68,16 @@ func (b *EventWriterBaseImpl) Run(ctx context.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
handlePaused := func() {
|
||||||
if b.GetPauseChan != nil {
|
if pause := b.GetPauseChan(); pause != nil {
|
||||||
pause := b.GetPauseChan()
|
select {
|
||||||
if pause != nil {
|
case <-pause:
|
||||||
select {
|
case <-ctx.Done():
|
||||||
case <-pause:
|
|
||||||
case <-ctx.Done():
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
|
@ -88,6 +86,8 @@ func (b *EventWriterBaseImpl) Run(ctx context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handlePaused()
|
||||||
|
|
||||||
if exprRegexp != nil {
|
if exprRegexp != nil {
|
||||||
fileLineCaller := fmt.Sprintf("%s:%d:%s", event.Origin.Filename, event.Origin.Line, event.Origin.Caller)
|
fileLineCaller := fmt.Sprintf("%s:%d:%s", event.Origin.Filename, event.Origin.Line, event.Origin.Caller)
|
||||||
matched := exprRegexp.Match([]byte(fileLineCaller)) || exprRegexp.Match([]byte(event.Origin.MsgSimpleText))
|
matched := exprRegexp.Match([]byte(fileLineCaller)) || exprRegexp.Match([]byte(event.Origin.MsgSimpleText))
|
||||||
|
|
Loading…
Reference in a new issue