Skip to content

Commit 586b879

Browse files
authored
print the raw ops log, when possible (#40)
1 parent 630f848 commit 586b879

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

pkg/producers/opslog/opslog.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package opslog
66

77
import (
88
"bufio"
9+
"bytes"
910
"fmt"
1011
"io"
1112
"net"
@@ -263,15 +264,17 @@ func processLogEntries(cfg OpsLogConfig, nc *nats.Conn, watcher *fsnotify.Watche
263264

264265
// Print to stdout if enabled
265266
if cfg.LogToStdout {
266-
var b []byte
267-
var err error
268267
if cfg.LogPrettyPrint {
269-
b, err = json.MarshalIndent(logEntry, "", " ")
268+
var buf bytes.Buffer
269+
if err := json.NewEncoder(&buf).Encode(json.RawMessage(str)); err == nil {
270+
var pretty bytes.Buffer
271+
if err := json.Indent(&pretty, buf.Bytes(), "", " "); err == nil {
272+
fmt.Println(pretty.String())
273+
}
274+
}
270275
} else {
271-
b, err = json.Marshal(logEntry)
272-
}
273-
if err == nil {
274-
fmt.Println(string(b))
276+
// Print the raw line
277+
fmt.Println(str)
275278
}
276279
}
277280

0 commit comments

Comments
 (0)