From 824a83c7ed296f5b46df7b6d4b166a2c3ddc5c18 Mon Sep 17 00:00:00 2001 From: lifeiyi <736926938@qq.com> Date: Fri, 19 Jun 2020 13:56:29 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=97=A5=E5=BF=97?= =?UTF-8?q?=EF=BC=8C=E6=8D=A2=E5=A4=A9=E5=88=87=E6=8D=A2=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- log/log.go | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/log/log.go b/log/log.go index 53d96fc..b289782 100644 --- a/log/log.go +++ b/log/log.go @@ -26,9 +26,12 @@ const ( ) type Logger struct { + filePath string + logTime time.Time level int baseLogger *log.Logger baseFile *os.File + flag int } func New(strLevel string, pathname string, flag int) (*Logger, error) { @@ -50,9 +53,8 @@ func New(strLevel string, pathname string, flag int) (*Logger, error) { // logger var baseLogger *log.Logger var baseFile *os.File + now := time.Now() if pathname != "" { - now := time.Now() - filename := fmt.Sprintf("%d%02d%02d_%02d_%02d_%02d.log", now.Year(), now.Month(), @@ -77,6 +79,9 @@ func New(strLevel string, pathname string, flag int) (*Logger, error) { logger.level = level logger.baseLogger = baseLogger logger.baseFile = baseFile + logger.logTime = now + logger.filePath = pathname + logger.flag = flag return logger, nil } @@ -99,6 +104,27 @@ func (logger *Logger) doPrintf(level int, printLevel string, format string, a .. panic("logger closed") } + if logger.baseFile != nil { + now := time.Now() + if now.Day() != logger.logTime.Day() { + filename := fmt.Sprintf("%d%02d%02d_%02d_%02d_%02d.log", + now.Year(), + now.Month(), + now.Day(), + now.Hour(), + now.Minute(), + now.Second()) + + file, err := os.Create(path.Join(logger.filePath, filename)) + if err == nil { + logger.baseFile.Close() + logger.baseLogger = log.New(file, "", logger.flag) + logger.baseFile = file + logger.logTime = now + } + } + } + format = printLevel + format logger.baseLogger.Output(3, fmt.Sprintf(format, a...)) From 500b3908e0872180c52865556e0260a620d98a5b Mon Sep 17 00:00:00 2001 From: lifeiyi <736926938@qq.com> Date: Mon, 29 Jun 2020 22:58:27 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dcall=E6=B2=A1=E6=89=BE?= =?UTF-8?q?=E5=88=B0=E5=AF=B9=E5=BA=94service=EF=BC=8C=E5=8D=A1=E6=AD=BB?= =?UTF-8?q?=E4=B8=8D=E6=AD=A3=E5=B8=B8=E8=BF=94=E5=9B=9E=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rpc/rpchandler.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rpc/rpchandler.go b/rpc/rpchandler.go index 8a221ad..dac257b 100644 --- a/rpc/rpchandler.go +++ b/rpc/rpchandler.go @@ -362,6 +362,9 @@ func (slf *RpcHandler) callRpc(nodeId int,serviceMethod string,args interface{}, //跨node调用 pCall := pClient.Go(false,serviceMethod,args,reply) + if pCall.Err != nil { + return pCall.Err + } pResult := pCall.Done() return pResult.Err }