Skip to content

Commit

Permalink
Added guard in case of broken pipe for streaming (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
aurc authored Jul 11, 2022
1 parent d7137a2 commit 178c6ef
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ loggo stream --file <my file> --template <my template yaml>
````
tail -f <my file> | loggo stream
````
Kubernetes example:
````
kubectl logs -f -n <namespace> <pod> | loggo stream
````
*With Template:*
````
tail -f <my file> | loggo stream --template <my template yaml>
Expand Down
3 changes: 2 additions & 1 deletion internal/reader/pipe_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"bufio"
"fmt"
"os"
"time"
)

type readPipeStream struct {
Expand All @@ -49,7 +50,7 @@ func (s *readPipeStream) StreamInto(strChan chan<- string) error {
for !s.stop {
str, err := reader.ReadString('\n')
if err != nil {
panic(err)
time.Sleep(time.Second)
}
strChan <- str
}
Expand Down
22 changes: 22 additions & 0 deletions internal/uitest/streamer/main_streamer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package main

import (
"fmt"

"github.com/aurc/loggo/internal/reader"
)

func main() {
streamReader := reader.MakeReader("")
streamReceiver := make(chan string, 1)
go streamReader.StreamInto(streamReceiver)
for {
line, ok := <-streamReceiver
if !ok {
break
}
if len(line) > 0 {
fmt.Printf("READER: %s", line)
}
}
}

0 comments on commit 178c6ef

Please sign in to comment.