Merge pull request #6611 from hashicorp/prettify_log_terminal_output

deduplicate logs that stream to terminal
This commit is contained in:
Megan Marsh 2018-08-21 15:40:22 -07:00 committed by GitHub
commit 41898ec7ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 0 deletions

17
log.go
View File

@ -1,8 +1,11 @@
package main
import (
"bufio"
"fmt"
"io"
"os"
"strings"
)
// These are the environmental variables that determine if we log, and if
@ -22,6 +25,20 @@ func logOutput() (logOutput io.Writer, err error) {
if err != nil {
return nil, err
}
} else {
// no path; do a little light filtering to avoid double-dipping UI
// calls.
r, w := io.Pipe()
scanner := bufio.NewScanner(r)
go func(scanner *bufio.Scanner) {
for scanner.Scan() {
if strings.Contains(scanner.Text(), "ui:") {
continue
}
os.Stderr.WriteString(fmt.Sprintf(scanner.Text() + "\n"))
}
}(scanner)
logOutput = w
}
}