Browse Source

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
tags/v1.20.0-rc0
wxiaoguang 1 year ago
parent
commit
0d54395fb5
No account linked to committer's email address
1 changed files with 9 additions and 9 deletions
  1. 9
    9
      modules/log/event_writer_base.go

+ 9
- 9
modules/log/event_writer_base.go View File

@@ -68,18 +68,16 @@ func (b *EventWriterBaseImpl) Run(ctx context.Context) {
}
}

for {
if b.GetPauseChan != nil {
pause := b.GetPauseChan()
if pause != nil {
select {
case <-pause:
case <-ctx.Done():
return
}
handlePaused := func() {
if pause := b.GetPauseChan(); pause != nil {
select {
case <-pause:
case <-ctx.Done():
}
}
}

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

handlePaused()

if exprRegexp != nil {
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))

Loading…
Cancel
Save