Browse Source

Merge pull request #156 from Leizhengzi/main

add logger interface defination
pull/158/head
yedf2 4 years ago
committed by GitHub
parent
commit
d0fe7b652a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      dtmcli/logger/log.go
  2. 12
      dtmcli/logger/logger_test.go
  3. 1
      dtmsvr/config/config.go
  4. 2
      dtmsvr/config/config_utils.go
  5. 1
      go.sum
  6. 2
      test/store_test.go

18
dtmcli/logger/log.go

@ -8,13 +8,27 @@ import (
"go.uber.org/zap/zapcore"
)
var logger *zap.SugaredLogger = nil
//var logger *zap.SugaredLogger = nil
var logger Logger = nil
func init() {
InitLog("info")
}
// InitLog is a initialization for a logger
// Logger logger interface
type Logger interface {
Debugf(format string, args ...interface{})
Infof(format string, args ...interface{})
Warnf(format string, args ...interface{})
Errorf(format string, args ...interface{})
}
func WithLogger(log Logger) {
logger = log
}
// InitLog is an initialization for a logger
// level can be: debug info warn error
func InitLog(level string) {
config := zap.NewProductionConfig()

12
dtmcli/logger/logger_test.go

@ -1,6 +1,7 @@
package logger
import (
"go.uber.org/zap"
"os"
"testing"
)
@ -15,3 +16,14 @@ func TestInitLog(t *testing.T) {
FatalfIf(false, "nothing")
FatalIfError(nil)
}
func TestWithLogger(t *testing.T) {
logger := zap.NewExample().Sugar()
WithLogger(logger)
Debugf("a debug msg")
Infof("a info msg")
Warnf("a warn msg")
Errorf("a error msg")
FatalfIf(false, "nothing")
FatalIfError(nil)
}

1
dtmsvr/config/config.go

@ -14,6 +14,7 @@ const (
Mysql = "mysql"
Redis = "redis"
BoltDb = "boltdb"
Postgres = "postgres"
)
// MicroService config type for micro service

2
dtmsvr/config/config_utils.go

@ -65,7 +65,7 @@ func checkConfig(conf *configType) error {
switch conf.Store.Driver {
case BoltDb:
return nil
case Mysql:
case Mysql, Postgres:
if conf.Store.Host == "" {
return errors.New("Db host not valid ")
}

1
go.sum

@ -476,6 +476,7 @@ github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=

2
test/store_test.go

@ -92,7 +92,7 @@ func TestStoreWait(t *testing.T) {
registry.WaitStoreUp()
}
func TestUpdateBranchSql(t *testing.T) {
func TestUpdateBranches(t *testing.T) {
if !conf.Store.IsDB() {
_, err := registry.GetStore().UpdateBranches(nil, nil)
assert.Nil(t, err)

Loading…
Cancel
Save