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") Errorf("a error msg")
FatalfIf(false, "nothing") FatalfIf(false, "nothing")
FatalIfError(nil) FatalIfError(nil)
s := lumberjackSink{&ll}
_ = s.Sync()
_ = os.Remove("test.log") _ = os.Remove("test.log")
} }

11
dtmsvr/svr.go

@ -20,23 +20,12 @@ import (
"github.com/dtm-labs/dtm/dtmutil" "github.com/dtm-labs/dtm/dtmutil"
"github.com/dtm-labs/dtmdriver" "github.com/dtm-labs/dtmdriver"
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware" grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
"github.com/natefinch/lumberjack"
"google.golang.org/grpc" "google.golang.org/grpc"
) )
// StartSvr StartSvr // StartSvr StartSvr
func StartSvr() { func StartSvr() {
logger.Infof("start dtmsvr") 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) 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 { 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) 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"
"github.com/dtm-labs/dtm/dtmsvr/config" "github.com/dtm-labs/dtm/dtmsvr/config"
"github.com/dtm-labs/dtm/dtmsvr/storage/registry" "github.com/dtm-labs/dtm/dtmsvr/storage/registry"
"github.com/natefinch/lumberjack"
// load the microserver driver // load the microserver driver
_ "github.com/dtm-labs/dtmdriver-gozero" _ "github.com/dtm-labs/dtmdriver-gozero"
@ -58,9 +59,23 @@ func main() {
return return
} }
config.MustLoadConfig(*confFile) config.MustLoadConfig(*confFile)
conf := &config.Config
if *isDebug { 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 { if *isReset {
dtmsvr.PopulateDB(false) dtmsvr.PopulateDB(false)
} }

Loading…
Cancel
Save