From 7beae5e81fada763b34cc8562cdcfe7c0d97cf58 Mon Sep 17 00:00:00 2001 From: huanghao Date: Sun, 16 Jan 2022 23:49:01 +0800 Subject: [PATCH 1/2] Update trans_xa_base.go --- dtmcli/dtmimp/trans_xa_base.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dtmcli/dtmimp/trans_xa_base.go b/dtmcli/dtmimp/trans_xa_base.go index 737f2a4..bcdb960 100644 --- a/dtmcli/dtmimp/trans_xa_base.go +++ b/dtmcli/dtmimp/trans_xa_base.go @@ -18,7 +18,7 @@ type XaClientBase struct { NotifyURL string } -// HandleCallback 处理commit/rollback的回调 +// HandleCallback Handle the callback of commit/rollback func (xc *XaClientBase) HandleCallback(gid string, branchID string, action string) error { db, err := StandaloneDB(xc.Conf) if err != nil { From 076b079bb21361b1d78171eb89b2ff20e88715bd Mon Sep 17 00:00:00 2001 From: yedf2 <120050102@qq.com> Date: Mon, 17 Jan 2022 08:35:29 +0800 Subject: [PATCH 2/2] cover more --- dtmcli/logger/logger_test.go | 2 ++ dtmsvr/svr.go | 11 ----------- main.go | 17 ++++++++++++++++- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/dtmcli/logger/logger_test.go b/dtmcli/logger/logger_test.go index bcba763..a63920f 100644 --- a/dtmcli/logger/logger_test.go +++ b/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") } diff --git a/dtmsvr/svr.go b/dtmsvr/svr.go index 8f25501..56f288c 100644 --- a/dtmsvr/svr.go +++ b/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) diff --git a/main.go b/main.go index 43ce895..4c6263f 100644 --- a/main.go +++ b/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) }