MCPcopy Create free account
hub / github.com/containerd/nerdctl / startTail

Function startTail

pkg/logging/logging.go:447–472  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

445// the boolean value indicates if the log file was recreated;
446// the error is error happens during waiting new logs.
447func 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}

Callers 2

ReadLogsFunction · 0.85
viewLogsJSONFileDirectFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…