Follow continuously fetches logs using the provided fetcher function and renders them to the provided writer. It stops when Render indicates to stop.
(fetcher func() ([]byte, error), w io.Writer, io *iostreams.IOStreams)
| 29 | // Follow continuously fetches logs using the provided fetcher function and |
| 30 | // renders them to the provided writer. It stops when Render indicates to stop. |
| 31 | func (r *logRenderer) Follow(fetcher func() ([]byte, error), w io.Writer, io *iostreams.IOStreams) error { |
| 32 | var last string |
| 33 | for { |
| 34 | raw, err := fetcher() |
| 35 | if err != nil { |
| 36 | return err |
| 37 | } |
| 38 | |
| 39 | logs := string(raw) |
| 40 | if logs == last { |
| 41 | continue |
| 42 | } |
| 43 | |
| 44 | diff := strings.TrimSpace(logs[len(last):]) |
| 45 | |
| 46 | if stop, err := r.Render([]byte(diff), w, io); err != nil { |
| 47 | return err |
| 48 | } else if stop { |
| 49 | return nil |
| 50 | } |
| 51 | |
| 52 | last = logs |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | // Render processes the given logs and writes the rendered output to w. |
| 57 | // Errors are returned when an unexpected log entry is encountered. |