fix(pkg/logger): exclude logger library into an own repository
This commit is contained in:
parent
bacddcfbf9
commit
ea83d43cd6
@ -7,7 +7,7 @@ import (
|
|||||||
"github.com/Masterminds/semver"
|
"github.com/Masterminds/semver"
|
||||||
"github.com/go-flucky/flucky/pkg/config"
|
"github.com/go-flucky/flucky/pkg/config"
|
||||||
"github.com/go-flucky/flucky/pkg/daemon"
|
"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"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
10
go.mod
10
go.mod
@ -12,17 +12,13 @@ require (
|
|||||||
github.com/docker/go-connections v0.4.0 // indirect
|
github.com/docker/go-connections v0.4.0 // indirect
|
||||||
github.com/docker/go-units v0.4.0 // indirect
|
github.com/docker/go-units v0.4.0 // indirect
|
||||||
github.com/go-flucky/go-dht v0.1.1
|
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/lib/pq v1.2.0
|
||||||
github.com/opencontainers/go-digest v1.0.0-rc1 // indirect
|
github.com/opencontainers/go-digest v1.0.0-rc1 // indirect
|
||||||
github.com/pkg/errors v0.8.1 // indirect
|
github.com/pkg/errors v0.8.1 // indirect
|
||||||
github.com/satori/go.uuid v1.2.0
|
github.com/satori/go.uuid v1.2.0
|
||||||
github.com/spf13/cobra v0.0.3
|
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/stianeikeland/go-rpio v4.2.0+incompatible
|
||||||
github.com/stretchr/testify v1.3.0
|
github.com/stretchr/testify v1.4.0
|
||||||
golang.org/x/tools v0.0.0-20190830223141-573d9926052a
|
github.com/volker-raschek/go-logger v0.0.0-20190924132822-0c50a64d7f26
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
|
golang.org/x/tools v0.0.0-20190830223141-573d9926052a // indirect
|
||||||
periph.io/x/periph v3.4.0+incompatible
|
|
||||||
)
|
)
|
||||||
|
8
go.sum
8
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-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 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw=
|
||||||
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
|
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 h1:dPz9F5D7oUaTd0GUGTvT4lBH2R043h1bkmhTlpQax1Y=
|
||||||
github.com/go-flucky/go-dht v0.1.1/go.mod h1:Yk/cct+/u+eCS7pB/kc0tc7MrVXdFI4W15MJCj5FRUc=
|
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=
|
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/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 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
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/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 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
|
||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
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 h1:XAHT1kdPpnU8Hk+FPi42KZFhtNFEk4vBg1U4OmIeHTU=
|
||||||
golang.org/x/tools v0.0.0-20190830223141-573d9926052a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
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=
|
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 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
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 h1:5gzxE4ryPq52cdqSw0mErR6pyJK8cBF2qdUAcOWh0bo=
|
||||||
periph.io/x/periph v3.4.0+incompatible/go.mod h1:EWr+FCIU2dBWz5/wSWeiIUJTriYv9v2j2ENBmgYyy7Y=
|
periph.io/x/periph v3.4.0+incompatible/go.mod h1:EWr+FCIU2dBWz5/wSWeiIUJTriYv9v2j2ENBmgYyy7Y=
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
"github.com/Masterminds/semver"
|
"github.com/Masterminds/semver"
|
||||||
"github.com/go-flucky/flucky/pkg/config"
|
"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/rgbled"
|
||||||
"github.com/go-flucky/flucky/pkg/sensor"
|
"github.com/go-flucky/flucky/pkg/sensor"
|
||||||
"github.com/go-flucky/flucky/pkg/storage/db"
|
"github.com/go-flucky/flucky/pkg/storage/db"
|
||||||
|
@ -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,
|
|
||||||
}
|
|
||||||
}
|
|
@ -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])
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
package logger
|
|
||||||
|
|
||||||
type Logger interface {
|
|
||||||
Debug(string, ...interface{})
|
|
||||||
Info(string, ...interface{})
|
|
||||||
Warn(string, ...interface{})
|
|
||||||
Error(string, ...interface{})
|
|
||||||
Fatal(string, ...interface{})
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package logger
|
|
||||||
|
|
||||||
type LogLevel int
|
|
||||||
|
|
||||||
const (
|
|
||||||
LogLevelDebug LogLevel = iota + 1
|
|
||||||
LogLevelInfo
|
|
||||||
LogLevelWarn
|
|
||||||
LogLevelError
|
|
||||||
LogLevelFatal
|
|
||||||
)
|
|
@ -5,7 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/go-flucky/flucky/pkg/config"
|
"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"
|
_ "github.com/lib/pq"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user