Loads log entries from logfiles produced by the json-logger driver and forwards them to the provided io.Writers after applying the provided logging options.
(lvopts LogViewOptions, stdout, stderr io.Writer, stopChannel chan os.Signal)
| 143 | // Loads log entries from logfiles produced by the json-logger driver and forwards |
| 144 | // them to the provided io.Writers after applying the provided logging options. |
| 145 | func viewLogsJSONFile(lvopts LogViewOptions, stdout, stderr io.Writer, stopChannel chan os.Signal) error { |
| 146 | logFilePath := jsonfile.Path(lvopts.DatastoreRootPath, lvopts.Namespace, lvopts.ContainerID) |
| 147 | if _, err := os.Stat(logFilePath); err != nil { |
| 148 | // FIXME: this is a workaround for the actual issue, not a real solution |
| 149 | // https://github.com/containerd/nerdctl/issues/3187 |
| 150 | if errors.Is(err, os.ErrNotExist) { |
| 151 | log.L.Warnf("Racing log file creation. Pausing briefly.") |
| 152 | time.Sleep(200 * time.Millisecond) |
| 153 | _, err = os.Stat(logFilePath) |
| 154 | } |
| 155 | if err != nil { |
| 156 | return fmt.Errorf("failed to stat JSON log file %w", err) |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | return viewLogsJSONFileDirect(lvopts, logFilePath, stdout, stderr, stopChannel) |
| 161 | } |
| 162 | |
| 163 | // Loads JSON log entries directly from the provided JSON log file. |
| 164 | // If `LogViewOptions.Follow` is provided, it will refresh and re-read the file until |
nothing calls this directly
no test coverage detected
searching dependent graphs…