diff options
author | Arne Juul <arnej@yahooinc.com> | 2022-08-18 10:40:08 +0000 |
---|---|---|
committer | Arne Juul <arnej@yahooinc.com> | 2022-08-18 10:40:08 +0000 |
commit | 4c80fc1991a3ff8cc605ef9c1e1684d055f1f9a7 (patch) | |
tree | 4af024f90bebdfa8527ca3152c0b4cdaca7a051a /client | |
parent | c6d747e7f832bd24b21216af6437bb76f62c51ef (diff) |
only format stdin if it is a pipe
* this was the old perl logic and is better for automation
Diffstat (limited to 'client')
-rw-r--r-- | client/go/cmd/logfmt/runlogfmt.go | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/client/go/cmd/logfmt/runlogfmt.go b/client/go/cmd/logfmt/runlogfmt.go index 9d782692f50..e3b3a0a3a78 100644 --- a/client/go/cmd/logfmt/runlogfmt.go +++ b/client/go/cmd/logfmt/runlogfmt.go @@ -8,12 +8,18 @@ import ( "bufio" "fmt" "os" - - "github.com/mattn/go-isatty" ) -func inputIsTty() bool { - return isatty.IsTerminal(os.Stdin.Fd()) +func inputIsPipe() bool { + fi, err := os.Stdin.Stat() + if err != nil { + return false + } + if fi.Mode()&os.ModeNamedPipe == 0 { + return false + } else { + return true + } } func vespaHome() string { @@ -28,7 +34,7 @@ func vespaHome() string { func RunLogfmt(opts *Options, args []string) { if len(args) == 0 { - if inputIsTty() { + if !inputIsPipe() { args = append(args, vespaHome()+"/logs/vespa/vespa.log") } else { formatFile(opts, os.Stdin) |