Browse Source

cover more

pull/184/head
yedf2 4 years ago
parent
commit
076b079bb2
  1. 2
      dtmcli/logger/logger_test.go
  2. 11
      dtmsvr/svr.go
  3. 17
      main.go

2
dtmcli/logger/logger_test.go

@ -46,5 +46,7 @@ func TestInitRotateLog(t *testing.T) {
Errorf("a error msg")
FatalfIf(false, "nothing")
FatalIfError(nil)
s := lumberjackSink{&ll}
_ = s.Sync()
_ = os.Remove("test.log")
}

11
dtmsvr/svr.go

@ -20,23 +20,12 @@ import (
"github.com/dtm-labs/dtm/dtmutil"
"github.com/dtm-labs/dtmdriver"
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
"github.com/natefinch/lumberjack"
"google.golang.org/grpc"
)
// StartSvr StartSvr
func StartSvr() {
logger.Infof("start dtmsvr")
if conf.Log.Output == "file" {
ll := lumberjack.Logger{
Filename: conf.Log.FileName,
MaxSize: int(conf.Log.FileMaxSize),
MaxBackups: int(conf.Log.FileMaxBackups),
MaxAge: int(conf.Log.FileMaxAge),
Compress: conf.Log.FileCompress != 0,
}
logger.InitRotateLog(conf.Log.Level, &ll)
}
dtmcli.GetRestyClient().SetTimeout(time.Duration(conf.RequestTimeout) * time.Second)
dtmgrpc.AddUnaryInterceptor(func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
ctx2, cancel := context.WithTimeout(ctx, time.Duration(conf.RequestTimeout)*time.Second)

17
main.go

@ -18,6 +18,7 @@ import (
"github.com/dtm-labs/dtm/dtmsvr"
"github.com/dtm-labs/dtm/dtmsvr/config"
"github.com/dtm-labs/dtm/dtmsvr/storage/registry"
"github.com/natefinch/lumberjack"
// load the microserver driver
_ "github.com/dtm-labs/dtmdriver-gozero"
@ -58,9 +59,23 @@ func main() {
return
}
config.MustLoadConfig(*confFile)
conf := &config.Config
if *isDebug {
config.Config.Log.Level = "debug"
conf.Log.Level = "debug"
}
if conf.Log.Output == "file" {
ll := lumberjack.Logger{
Filename: conf.Log.FileName,
MaxSize: int(conf.Log.FileMaxSize),
MaxBackups: int(conf.Log.FileMaxBackups),
MaxAge: int(conf.Log.FileMaxAge),
Compress: conf.Log.FileCompress != 0,
}
logger.InitRotateLog(conf.Log.Level, &ll)
} else {
logger.InitLog(conf.Log.Level)
}
if *isReset {
dtmsvr.PopulateDB(false)
}

Loading…
Cancel
Save