Skip to content

Commit

Permalink
fix: use stdcopy.StdCopy to send logs to pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
neurosnap committed Nov 23, 2024
1 parent 13c1d7c commit 7b9dd32
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"bufio"
"context"
"flag"
"io"
Expand All @@ -16,6 +15,7 @@ import (
ct "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/events"
"github.com/docker/docker/client"
"github.com/docker/docker/pkg/stdcopy"
"github.com/picosh/utils/pipe"
)

Expand Down Expand Up @@ -71,13 +71,9 @@ func containerStart(ctx context.Context, logger *slog.Logger, client *client.Cli
}

go func() {
scanner := bufio.NewScanner(readCloser)
for scanner.Scan() {
line := scanner.Text()
_, err = reconn.Write([]byte(line + "\n"))
if err != nil {
logger.Error("cannot write to pipe topic", "err", err)
}
_, err = stdcopy.StdCopy(reconn, reconn, readCloser)
if err != nil {
logger.Error("cannot write to pipe topic", "err", err)
}
}()

Expand Down

0 comments on commit 7b9dd32

Please sign in to comment.