From ea83d43cd60268e431af9409d3f86010c7e23d5d Mon Sep 17 00:00:00 2001 From: Markus Pesch Date: Tue, 24 Sep 2019 15:34:14 +0200 Subject: [PATCH] fix(pkg/logger): exclude logger library into an own repository --- cmd/daemon/daemon.go | 2 +- go.mod | 10 ++-- go.sum | 8 ++++ pkg/daemon/daemon.go | 2 +- pkg/logger/default.go | 93 -------------------------------------- pkg/logger/default_test.go | 69 ---------------------------- pkg/logger/interface.go | 9 ---- pkg/logger/loglevel.go | 11 ----- pkg/storage/db/db.go | 2 +- 9 files changed, 14 insertions(+), 192 deletions(-) delete mode 100644 pkg/logger/default.go delete mode 100644 pkg/logger/default_test.go delete mode 100644 pkg/logger/interface.go delete mode 100644 pkg/logger/loglevel.go diff --git a/cmd/daemon/daemon.go b/cmd/daemon/daemon.go index 0b3b96f..0db6ce8 100644 --- a/cmd/daemon/daemon.go +++ b/cmd/daemon/daemon.go @@ -7,7 +7,7 @@ import ( "github.com/Masterminds/semver" "github.com/go-flucky/flucky/pkg/config" "github.com/go-flucky/flucky/pkg/daemon" - "github.com/go-flucky/flucky/pkg/logger" + "github.com/volker-raschek/go-logger/pkg/logger" "github.com/spf13/cobra" ) diff --git a/go.mod b/go.mod index 9b554e9..bc1968d 100644 --- a/go.mod +++ b/go.mod @@ -12,17 +12,13 @@ require ( github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-units v0.4.0 // indirect github.com/go-flucky/go-dht v0.1.1 - github.com/inconshreveable/mousetrap v1.0.0 // indirect - github.com/kr/pretty v0.1.0 // indirect github.com/lib/pq v1.2.0 github.com/opencontainers/go-digest v1.0.0-rc1 // indirect github.com/pkg/errors v0.8.1 // indirect github.com/satori/go.uuid v1.2.0 github.com/spf13/cobra v0.0.3 - github.com/spf13/pflag v1.0.3 // indirect github.com/stianeikeland/go-rpio v4.2.0+incompatible - github.com/stretchr/testify v1.3.0 - golang.org/x/tools v0.0.0-20190830223141-573d9926052a - gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect - periph.io/x/periph v3.4.0+incompatible + github.com/stretchr/testify v1.4.0 + github.com/volker-raschek/go-logger v0.0.0-20190924132822-0c50a64d7f26 + golang.org/x/tools v0.0.0-20190830223141-573d9926052a // indirect ) diff --git a/go.sum b/go.sum index a0dae3d..060b6f5 100644 --- a/go.sum +++ b/go.sum @@ -16,6 +16,7 @@ github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKoh github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw= github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= +github.com/go-flucky/flucky v0.0.0-20190714170626-0dd156f480be/go.mod h1:WNT729lCsTFhT6Vyvg6cG8aHV1t6p+DsA8l4omOuaos= github.com/go-flucky/go-dht v0.1.1 h1:dPz9F5D7oUaTd0GUGTvT4lBH2R043h1bkmhTlpQax1Y= github.com/go-flucky/go-dht v0.1.1/go.mod h1:Yk/cct+/u+eCS7pB/kc0tc7MrVXdFI4W15MJCj5FRUc= github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= @@ -44,6 +45,10 @@ github.com/stianeikeland/go-rpio v4.2.0+incompatible/go.mod h1:Sh81rdJwD96E2wja2 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/volker-raschek/go-logger v0.0.0-20190924132822-0c50a64d7f26 h1:7xmCI9JL1pIsiv3ACpadGxpHZd96TP7pcT7iWK2IF+g= +github.com/volker-raschek/go-logger v0.0.0-20190924132822-0c50a64d7f26/go.mod h1:V4TEAy1Kx45GPlB2VvS5mVpNfSksNDDuEgk7wm7cd0k= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -53,7 +58,10 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/tools v0.0.0-20190830223141-573d9926052a h1:XAHT1kdPpnU8Hk+FPi42KZFhtNFEk4vBg1U4OmIeHTU= golang.org/x/tools v0.0.0-20190830223141-573d9926052a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= periph.io/x/periph v3.4.0+incompatible h1:5gzxE4ryPq52cdqSw0mErR6pyJK8cBF2qdUAcOWh0bo= periph.io/x/periph v3.4.0+incompatible/go.mod h1:EWr+FCIU2dBWz5/wSWeiIUJTriYv9v2j2ENBmgYyy7Y= diff --git a/pkg/daemon/daemon.go b/pkg/daemon/daemon.go index eb0efc4..fbeb0c0 100644 --- a/pkg/daemon/daemon.go +++ b/pkg/daemon/daemon.go @@ -9,7 +9,7 @@ import ( "github.com/Masterminds/semver" "github.com/go-flucky/flucky/pkg/config" - "github.com/go-flucky/flucky/pkg/logger" + "github.com/volker-raschek/go-logger/pkg/logger" "github.com/go-flucky/flucky/pkg/rgbled" "github.com/go-flucky/flucky/pkg/sensor" "github.com/go-flucky/flucky/pkg/storage/db" diff --git a/pkg/logger/default.go b/pkg/logger/default.go deleted file mode 100644 index 45cf72e..0000000 --- a/pkg/logger/default.go +++ /dev/null @@ -1,93 +0,0 @@ -package logger - -import ( - "fmt" - "io" - "io/ioutil" - "os" - "sync" - "time" -) - -type defaultLogger struct { - logLevel LogLevel - mutex *sync.Mutex - stdout io.Writer - stderr io.Writer -} - -func (dl *defaultLogger) Debug(f string, v ...interface{}) { - dl.log(LogLevelDebug, f, v...) -} - -func (dl *defaultLogger) Info(f string, v ...interface{}) { - dl.log(LogLevelInfo, f, v...) -} - -func (dl *defaultLogger) Warn(f string, v ...interface{}) { - dl.log(LogLevelWarn, f, v...) -} - -func (dl *defaultLogger) Error(f string, v ...interface{}) { - dl.log(LogLevelError, f, v...) -} - -func (dl *defaultLogger) Fatal(f string, v ...interface{}) { - dl.log(LogLevelFatal, f, v...) - os.Exit(1) -} - -func (dl *defaultLogger) log(ll LogLevel, f string, v ...interface{}) { - - if dl.logLevel > ll { - return - } - - layout := "2006/01/02 15:04:05" - dw := dl.stdout - prefix := "" - switch ll { - case LogLevelDebug: - prefix = "DEBUG" - case LogLevelInfo: - prefix = "INFO" - case LogLevelWarn: - prefix = "WARN" - case LogLevelError: - prefix = "ERROR" - dw = dl.stderr - case LogLevelFatal: - prefix = "FATAL" - dw = dl.stderr - } - dl.mutex.Lock() - fmt.Fprintf(dw, "%v %v: %v\n", time.Now().Format(layout), prefix, fmt.Sprintf(f, v...)) - dl.mutex.Unlock() -} - -func NewDefaultLogger(logLevel LogLevel) Logger { - return &defaultLogger{ - logLevel: logLevel, - mutex: new(sync.Mutex), - stdout: os.Stdout, - stderr: os.Stderr, - } -} - -func NewCustomLogger(loglevel LogLevel, out io.Writer, err io.Writer) Logger { - return &defaultLogger{ - logLevel: loglevel, - mutex: new(sync.Mutex), - stdout: out, - stderr: err, - } -} - -func NewSilentLogger() Logger { - return &defaultLogger{ - logLevel: LogLevelDebug, - mutex: new(sync.Mutex), - stdout: ioutil.Discard, - stderr: ioutil.Discard, - } -} diff --git a/pkg/logger/default_test.go b/pkg/logger/default_test.go deleted file mode 100644 index dd28f54..0000000 --- a/pkg/logger/default_test.go +++ /dev/null @@ -1,69 +0,0 @@ -package logger_test - -import ( - "bytes" - "strings" - "testing" - - "github.com/go-flucky/flucky/pkg/logger" - "github.com/stretchr/testify/require" -) - -func TestLogger(t *testing.T) { - require := require.New(t) - stdoutBuffer := new(bytes.Buffer) - stderrBuffer := new(bytes.Buffer) - - // LogLevelDebug - l := logger.NewCustomLogger(logger.LogLevelDebug, stdoutBuffer, stderrBuffer) - l.Debug("DEBUG") - require.NotEmpty(stdoutBuffer.Bytes()) - require.Empty(stderrBuffer.Bytes()) - - stdoutBuffer.Reset() - stderrBuffer.Reset() - - // LogLevelInfo - l = logger.NewCustomLogger(logger.LogLevelInfo, stdoutBuffer, stderrBuffer) - - l.Debug("DEBUG") - require.Empty(stdoutBuffer.Bytes()) - require.Empty(stderrBuffer.Bytes()) - - stdoutBuffer.Reset() - stderrBuffer.Reset() - - l.Info("INFO") - require.NotEmpty(stdoutBuffer.Bytes()) - require.Empty(stderrBuffer.Bytes()) - - stringArray := strings.Split(stdoutBuffer.String(), ": ") - require.Equal(2, len(stringArray)) - require.Equal("INFO\n", stringArray[1]) - - stdoutBuffer.Reset() - stderrBuffer.Reset() - - // LogLevelWarn - l = logger.NewCustomLogger(logger.LogLevelWarn, stdoutBuffer, stderrBuffer) - l.Warn("WARN") - require.NotEmpty(stdoutBuffer.Bytes()) - require.Empty(stderrBuffer.Bytes()) - - stringArray = strings.Split(stdoutBuffer.String(), ": ") - require.Equal(2, len(stringArray)) - require.Equal("WARN\n", stringArray[1]) - - stdoutBuffer.Reset() - stderrBuffer.Reset() - - // LogLevelError - l = logger.NewCustomLogger(logger.LogLevelError, stdoutBuffer, stderrBuffer) - l.Error("ERROR") - require.Empty(stdoutBuffer.Bytes()) - require.NotEmpty(stderrBuffer.Bytes()) - - stringArray = strings.Split(stderrBuffer.String(), ": ") - require.Equal(2, len(stringArray)) - require.Equal("ERROR\n", stringArray[1]) -} diff --git a/pkg/logger/interface.go b/pkg/logger/interface.go deleted file mode 100644 index 5d78fe9..0000000 --- a/pkg/logger/interface.go +++ /dev/null @@ -1,9 +0,0 @@ -package logger - -type Logger interface { - Debug(string, ...interface{}) - Info(string, ...interface{}) - Warn(string, ...interface{}) - Error(string, ...interface{}) - Fatal(string, ...interface{}) -} diff --git a/pkg/logger/loglevel.go b/pkg/logger/loglevel.go deleted file mode 100644 index 71ecfbf..0000000 --- a/pkg/logger/loglevel.go +++ /dev/null @@ -1,11 +0,0 @@ -package logger - -type LogLevel int - -const ( - LogLevelDebug LogLevel = iota + 1 - LogLevelInfo - LogLevelWarn - LogLevelError - LogLevelFatal -) diff --git a/pkg/storage/db/db.go b/pkg/storage/db/db.go index bc5d50a..8a3e191 100644 --- a/pkg/storage/db/db.go +++ b/pkg/storage/db/db.go @@ -5,7 +5,7 @@ import ( "fmt" "github.com/go-flucky/flucky/pkg/config" - "github.com/go-flucky/flucky/pkg/logger" + "github.com/volker-raschek/go-logger/pkg/logger" _ "github.com/lib/pq" )