Skip to content

Commit d402cf8

Browse files
authored
Silent amplitude logger (#20)
* Silent amplitude logger * cleanup makefile
1 parent 446083b commit d402cf8

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

makefile

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: all setup build lint test install
1+
.PHONY: all setup build run lint test
22

33
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null | sed 's/^v//')
44
COMMIT ?= $(shell git rev-parse --short=12 HEAD 2>/dev/null || echo "unknown")
@@ -15,13 +15,11 @@ all: lint test build
1515
setup: bin/golangci-lint
1616
go mod download
1717

18-
dune-cli: lint
18+
build: lint
1919
go build -ldflags '$(LDFLAGS)' -o dune-cli ./cmd
2020

21-
build: dune-cli
22-
23-
install:
24-
go build -ldflags '$(LDFLAGS)' -o $(shell go env GOPATH)/bin/dune ./cmd
21+
run:
22+
go run -ldflags '$(LDFLAGS)' ./cmd $(ARGS)
2523

2624
bin:
2725
mkdir -p bin

tracking/tracking.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ func New(cfg Config) *Tracker {
3939
ampConfig.ServerZone = "EU"
4040
ampConfig.FlushQueueSize = 1
4141
ampConfig.FlushInterval = 1 * time.Second
42+
if !isDevVersion(cfg.CLIVersion) {
43+
ampConfig.Logger = silentLogger{}
44+
}
4245

4346
return &Tracker{
4447
client: amplitude.NewClient(ampConfig),
@@ -76,6 +79,19 @@ func (t *Tracker) Shutdown() {
7679
}
7780
}
7881

82+
// isDevVersion returns true for local / non-release builds.
83+
func isDevVersion(v string) bool {
84+
return v == "" || v == "dev"
85+
}
86+
87+
// silentLogger suppresses all amplitude SDK log output.
88+
type silentLogger struct{}
89+
90+
func (silentLogger) Debugf(string, ...interface{}) {}
91+
func (silentLogger) Infof(string, ...interface{}) {}
92+
func (silentLogger) Warnf(string, ...interface{}) {}
93+
func (silentLogger) Errorf(string, ...interface{}) {}
94+
7995
const (
8096
anonIDFile = "anonymous_id"
8197
anonFallback = "anonymous"

0 commit comments

Comments
 (0)