From f5694cb227217268f8329d3c0b81d4633f2b92e2 Mon Sep 17 00:00:00 2001 From: wucongxing8150 <815046773@qq.com> Date: Wed, 29 May 2024 15:45:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/service/v1/Coupon.go | 13 +++++++------ utils/logger.go | 15 ++++++++++++++- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/api/service/v1/Coupon.go b/api/service/v1/Coupon.go index 0379e72..51a0b13 100644 --- a/api/service/v1/Coupon.go +++ b/api/service/v1/Coupon.go @@ -257,12 +257,13 @@ func (r *CouponService) ReceiveCoupon(req requestsV1.ReceiveCoupon) (g *dtoV1.Re return nil, err } - // 发送通知 - res, _ := service.PatientDistributeCoupon(coupon.CouponName, user.UserId) - if !res { - utils.LogJsonInfo("优惠卷通知发送失败") - } - + go func() { + // 发送通知 + res, _ := service.PatientDistributeCoupon(coupon.CouponName, user.UserId) + if !res { + utils.LogJsonError("优惠卷通知发送失败") + } + }() } } diff --git a/utils/logger.go b/utils/logger.go index 612bc03..f297a44 100644 --- a/utils/logger.go +++ b/utils/logger.go @@ -15,9 +15,22 @@ func LogJsonInfo(v interface{}) { } jsonString := string(jsonData) - fmt.Println(jsonString) global.Logger.WithFields(logrus.Fields{ "data": jsonString, }).Info("info") } + +func LogJsonError(v interface{}) { + jsonData, err := json.Marshal(v) + if err != nil { + fmt.Println("Error marshaling struct to JSON:", err) + return + } + + jsonString := string(jsonData) + + global.Logger.WithFields(logrus.Fields{ + "data": jsonString, + }).Info("error") +}