mirror of
https://github.com/psviderski/uncloud.git
synced 2026-10-08 22:24:54 +00:00
refactor: simplify journal logs following, fix corrosion unit name
This commit is contained in:
1 parent
e96cce88c1
commit
943fea0515
3 files changed
+11
-36
No files matched your search
@@ -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
|
||||
}
|
||||
Reference in new issue
Block a user