startTail wait for the next log write. the boolean value indicates if the log file was recreated; the error is error happens during waiting new logs.
(ctx context.Context, logName string, w *fsnotify.Watcher)
| 445 | // the boolean value indicates if the log file was recreated; |
| 446 | // the error is error happens during waiting new logs. |
| 447 | func startTail(ctx context.Context, logName string, w *fsnotify.Watcher) (bool, error) { |
| 448 | errRetry := 5 |
| 449 | for { |
| 450 | select { |
| 451 | case <-ctx.Done(): |
| 452 | return false, fmt.Errorf("context cancelled") |
| 453 | case e := <-w.Events: |
| 454 | switch { |
| 455 | case e.Has(fsnotify.Write): |
| 456 | return false, nil |
| 457 | case e.Has(fsnotify.Create): |
| 458 | return filepath.Base(e.Name) == logName, nil |
| 459 | default: |
| 460 | log.L.Debugf("Received unexpected fsnotify event: %v, retrying", e) |
| 461 | } |
| 462 | case err := <-w.Errors: |
| 463 | log.L.WithError(err).Debugf("Received fsnotify watch error, retrying unless no more retries left, retries: %d", errRetry) |
| 464 | if errRetry == 0 { |
| 465 | return false, err |
| 466 | } |
| 467 | errRetry-- |
| 468 | case <-time.After(logForceCheckPeriod): |
| 469 | return false, nil |
| 470 | } |
| 471 | } |
| 472 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…