refactor: simplify journal logs following, fix corrosion unit name

This commit is contained in:
Pasha Sviderski
2026-04-08 19:38:02 +10:00
parent e96cce88c1
commit 943fea0515
3 changed files with 11 additions and 36 deletions
+3 -3
View File
@@ -52,18 +52,18 @@ func logs(ctx context.Context, unit string, opts api.ServiceLogsOptions) (io.Rea
}
// follow synchronously follows the io.Reader, writing each new journal entry to channel.
func follow(ctx context.Context, reader io.Reader, outCh chan api.LogEntry) error {
// It stops when the reader is exhausted or the context is cancelled.
func follow(ctx context.Context, reader io.Reader, outCh chan api.LogEntry) {
scanner := bufio.NewScanner(reader)
for scanner.Scan() {
select {
case outCh <- entry(scanner.Bytes()):
case <-ctx.Done():
return nil
return
}
}
if err := scanner.Err(); err != nil {
outCh <- api.LogEntry{Err: fmt.Errorf("journal logs: %w", err)}
}
return nil
}