Skip to content

Commit 0d54395

Browse files
authored
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
1 parent 7314726 commit 0d54395

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

modules/log/event_writer_base.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,16 @@ func (b *EventWriterBaseImpl) Run(ctx context.Context) {
6868
}
6969
}
7070

71-
for {
72-
if b.GetPauseChan != nil {
73-
pause := b.GetPauseChan()
74-
if pause != nil {
75-
select {
76-
case <-pause:
77-
case <-ctx.Done():
78-
return
79-
}
71+
handlePaused := func() {
72+
if pause := b.GetPauseChan(); pause != nil {
73+
select {
74+
case <-pause:
75+
case <-ctx.Done():
8076
}
8177
}
78+
}
8279

80+
for {
8381
select {
8482
case <-ctx.Done():
8583
return
@@ -88,6 +86,8 @@ func (b *EventWriterBaseImpl) Run(ctx context.Context) {
8886
return
8987
}
9088

89+
handlePaused()
90+
9191
if exprRegexp != nil {
9292
fileLineCaller := fmt.Sprintf("%s:%d:%s", event.Origin.Filename, event.Origin.Line, event.Origin.Caller)
9393
matched := exprRegexp.Match([]byte(fileLineCaller)) || exprRegexp.Match([]byte(event.Origin.MsgSimpleText))

0 commit comments

Comments
 (0)