Skip to content

Commit dc8011e

Browse files
committed
Addressed issue #166
Now we use JSONL
1 parent e4deddd commit dc8011e

File tree

2 files changed

+4
-20
lines changed

2 files changed

+4
-20
lines changed

cmd/root_command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ func Execute(version, commit, date string, fs embed.FS) {
772772
rootCmd.Flags().StringP("har", "z", "", "Load a HAR file instead of sniffing traffic")
773773
rootCmd.Flags().BoolP("har-validate", "g", false, "Load a HAR file instead of sniffing traffic, and validate against the OpenAPI specification (requires -s)")
774774
rootCmd.Flags().StringArrayP("har-allow", "j", nil, "Add a path to the HAR allow list, can use arg multiple times")
775-
rootCmd.Flags().StringP("report-filename", "f", "wiretap-report.json", "Filename for any headless report generation output")
775+
rootCmd.Flags().StringP("report-filename", "f", "wiretap-report.jsonl", "Filename for any headless report generation output")
776776
rootCmd.Flags().BoolP("stream-report", "a", false, "Stream violations to report JSON file as they occur (headless mode)")
777777
rootCmd.Flags().BoolP("strict-redirect-location", "r", false, "Rewrite the redirect `Location` header on redirect responses to wiretap's API Gateway Host")
778778
rootCmd.Flags().Bool("strict-mode", false, "Enable strict validation to detect undeclared properties, parameters, headers, and cookies")

daemon/stream_output.go

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package daemon
55

66
import (
7-
"fmt"
87
jsoniter "github.com/json-iterator/go"
98
"github.com/pb33f/wiretap/shared"
109
"github.com/pterm/pterm"
@@ -27,33 +26,18 @@ func (ws *WiretapService) listenForValidationErrors() {
2726

2827
go func() {
2928
defer f.Close()
30-
if _, e := f.WriteString("[]"); e != nil {
31-
pterm.Error.Println("cannot write violation to stream: " + err.Error())
32-
}
3329
for {
3430
select {
3531
case violations := <-ws.streamChan:
36-
3732
if ws.stream {
3833
lock.Lock()
39-
40-
fi, _ := f.Stat()
41-
_ = os.Truncate(ws.reportFile, fi.Size()-1)
42-
if fi.Size() > 2 {
43-
_, _ = f.WriteString(",\n")
44-
}
4534
ws.streamViolations = append(ws.streamViolations, violations...)
46-
47-
for i, v := range violations {
35+
for _, v := range violations {
4836
bytes, _ := json.Marshal(v)
49-
if _, e := f.WriteString(fmt.Sprintf("%s", bytes)); e != nil {
50-
pterm.Error.Println("cannot write violation to stream: " + err.Error())
51-
}
52-
if i > len(violations)-1 {
53-
_, _ = f.WriteString(",\n")
37+
if _, e := f.WriteString(string(bytes) + "\n"); e != nil {
38+
pterm.Error.Println("cannot write violation to stream: " + e.Error())
5439
}
5540
}
56-
_, _ = f.WriteString("]")
5741
lock.Unlock()
5842
}
5943
}

0 commit comments

Comments
 (0)