From 660b2c759a26fa7cbbaa1c07ffdbb343c193ff66 Mon Sep 17 00:00:00 2001 From: xun Date: Wed, 13 Mar 2024 21:43:13 +0800 Subject: [PATCH] Update log format and level in project --- model/user.go | 14 +++++++------- service/user.go | 3 +++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/model/user.go b/model/user.go index bc5a921..947e4f1 100644 --- a/model/user.go +++ b/model/user.go @@ -53,7 +53,7 @@ func CheckPassword(username string, password string) (string, error) { var user User matched, regErr := regexp.MatchString("@", username) if regErr != nil { - userLogger.Infof("regexp matchiong error") + userLogger.Errorf("regexp matchiong error") return "", regErr } @@ -67,7 +67,7 @@ func CheckPassword(username string, password string) (string, error) { } if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { - userLogger.Infof("User [%s] Not Exist\n", username) + userLogger.Errorf("User [%s] Not Exist\n", username) return "", result.UserNotExist } } @@ -95,7 +95,7 @@ func GetUserByEmail(email string) (*User, error) { err := Db.Where("email = ?", email).Where("is_deleted = ?", false).First(&user).Error if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { - userLogger.Infof("User [%s] Not Exist\n", email) + userLogger.Errorf("User [%s] Not Exist\n", email) return nil, nil } return nil, result.InternalErr @@ -110,7 +110,7 @@ func GetUserByUid(uid string) (*User, error) { err := Db.Where("uid = ?", uid).Where("is_deleted = ?", false).First(&user).Error if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { - userLogger.Infof("User [%s] Not Exist\n", uid) + userLogger.Errorf("User [%s] Not Exist\n", uid) return nil, result.UserNotExist } return nil, err @@ -122,7 +122,7 @@ func UserInfo(username string) (*User, error) { var user = User{Uid: &username} matched, err2 := regexp.MatchString("@", username) if err2 != nil { - userLogger.Infof("regexp matchiong error") + userLogger.Errorf("regexp matchiong error") return nil, err2 } var err error = nil @@ -133,7 +133,7 @@ func UserInfo(username string) (*User, error) { } if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { - userLogger.Infof("User [%s] Not Exist\n", username) + userLogger.Errorf("User [%s] Not Exist\n", username) return nil, err } } @@ -168,7 +168,7 @@ func FindUserByGithubId(githubId string) (*User, error) { err := Db.Where("github_id = ?", githubId).Where("is_deleted = ?", false).First(&user).Error if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { - userLogger.Infof("User [%s] Not Exist\n", githubId) + userLogger.Errorf("User [%s] Not Exist\n", githubId) return nil, nil } return nil, err diff --git a/service/user.go b/service/user.go index 8157ea2..c047647 100644 --- a/service/user.go +++ b/service/user.go @@ -59,10 +59,13 @@ func VerifyAccount(ctx *gin.Context, username, flag string) (string, error) { // 1 is login // 2 is resetPassword if flag == "0" { + log.Log.Debugf("[%s] enter register verify\n", username) return VerifyAccountRegister(ctx, username) } else if flag == "1" { + log.Log.Debugf("[%s] enter login verify\n", username) return VerifyAccountLogin(ctx, username) } else if flag == "2" { + log.Log.Debugf("[%s] enter resetPWD verify\n", username) return VerifyAccountResetPWD(ctx, username) } else { return "", result.RequestParamError