From 9c820cf8558d60e5348fed8cef09f67c188fe81f Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Wed, 24 Mar 2021 11:39:45 +0100 Subject: [PATCH] fix(ooniprobe): send batch output to stdout (#261) Rationale explained in detail in a documentation comment. Reference issue: https://github.com/ooni/probe/issues/1384. --- cmd/ooniprobe/internal/log/handlers/batch/batch.go | 13 +++++++++++-- cmd/ooniprobe/internal/log/handlers/cli/cli.go | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/cmd/ooniprobe/internal/log/handlers/batch/batch.go b/cmd/ooniprobe/internal/log/handlers/batch/batch.go index 2b11371..2d06a4f 100644 --- a/cmd/ooniprobe/internal/log/handlers/batch/batch.go +++ b/cmd/ooniprobe/internal/log/handlers/batch/batch.go @@ -9,8 +9,17 @@ import ( "github.com/apex/log" ) -// Default handler outputting to stderr. -var Default = New(os.Stderr) +// Default handler outputting to stdout. We want to emit the batch +// output on the standard output, for two reasons: +// +// 1. because third party libraries MAY log on the stderr and +// their logs are most likely not JSON; +// +// 2. because this enables piping to `jq` or other tools in +// a much more natural way than when emitting on stderr. +// +// See https://github.com/ooni/probe/issues/1384. +var Default = New(os.Stdout) // Handler implementation. type Handler struct { diff --git a/cmd/ooniprobe/internal/log/handlers/cli/cli.go b/cmd/ooniprobe/internal/log/handlers/cli/cli.go index bd34346..575c922 100644 --- a/cmd/ooniprobe/internal/log/handlers/cli/cli.go +++ b/cmd/ooniprobe/internal/log/handlers/cli/cli.go @@ -14,7 +14,7 @@ import ( "github.com/ooni/probe-cli/v3/cmd/ooniprobe/internal/utils" ) -// Default handler outputting to stderr. +// Default handler outputting to stdout. var Default = New(os.Stdout) // start time.