summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorArnstein Ressem <aressem@verizonmedia.com>2022-08-19 10:41:45 +0200
committerGitHub <noreply@github.com>2022-08-19 10:41:45 +0200
commitf490b0591d0de1bcb0a714798716b56d3e9c8534 (patch)
tree28b2682954cd0a12444a5c2e0967306e8eeba2a3 /client
parent4a212822f767452dbccce34a81ee946ce5055b46 (diff)
parent17557659163d77afe865f937a785907dc29a375a (diff)
Merge pull request #23706 from vespa-engine/arnej/go-logfmt-take-2
Arnej/go logfmt take 2
Diffstat (limited to 'client')
-rw-r--r--client/CMakeLists.txt14
-rw-r--r--client/go/.gitignore1
-rw-r--r--client/go/Makefile3
-rw-r--r--client/go/cmd/logfmt/runlogfmt.go16
-rw-r--r--client/go/go.mod2
5 files changed, 29 insertions, 7 deletions
diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt
new file mode 100644
index 00000000000..1ca6d2b4e60
--- /dev/null
+++ b/client/CMakeLists.txt
@@ -0,0 +1,14 @@
+# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+set(GODIR ${CMAKE_CURRENT_SOURCE_DIR}/go)
+
+file(GLOB_RECURSE GOSRCFILES ${GODIR}/*.go)
+
+add_custom_command(OUTPUT ${GODIR}/bin/vespa-logfmt
+ COMMAND make
+ DEPENDS ${GODIR}/Makefile ${GOSRCFILES}
+ WORKING_DIRECTORY ${GODIR})
+
+add_custom_target(vespalog_logfmt ALL DEPENDS ${GODIR}/bin/vespa-logfmt)
+
+install(PROGRAMS ${GODIR}/bin/vespa-logfmt DESTINATION bin)
diff --git a/client/go/.gitignore b/client/go/.gitignore
index 8933bc220cb..baab7c638c6 100644
--- a/client/go/.gitignore
+++ b/client/go/.gitignore
@@ -6,3 +6,4 @@ share/
!target/
mytestapp/
mytestapp-cache/
+mytmp/
diff --git a/client/go/Makefile b/client/go/Makefile
index 78adf299f0e..8a07f880c24 100644
--- a/client/go/Makefile
+++ b/client/go/Makefile
@@ -131,7 +131,8 @@ clean:
rmdir -p $(BIN) $(SHARE)/man/man1 > /dev/null 2>&1 || true
test: ci
- go test ./...
+ mkdir -p mytmp
+ TMPDIR=`pwd`/mytmp go test ./...
checkfmt:
@bash -c "diff --line-format='%L' <(echo -n) <(gofmt -l .)" || { echo "one or more files need to be formatted: try make fmt to fix this automatically"; exit 1; }
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)
diff --git a/client/go/go.mod b/client/go/go.mod
index 15b45a291a6..4181d4ee2f2 100644
--- a/client/go/go.mod
+++ b/client/go/go.mod
@@ -17,7 +17,7 @@ require (
github.com/stretchr/objx v0.1.1 // indirect
github.com/stretchr/testify v1.7.0
github.com/zalando/go-keyring v0.1.1
- golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
+ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
)