diff --git a/controllers/user_controller.go b/controllers/user_controller.go index e0f1c97..f89edbe 100644 --- a/controllers/user_controller.go +++ b/controllers/user_controller.go @@ -37,6 +37,7 @@ func RegisterUser(c *gin.Context) { globals.SugarLogger.Debugf("End API :%s error:%v:", c.Request.URL, err) return } + globals.SugarLogger.Debugf("Begin API :%s params: %v ip: %s", c.Request.URL, utils.Format4Output(user, true)) if !captchaVerify(c, user.Code) { c.JSON(http.StatusOK, &CallBack{ Code: model.ErrCodeNormal, diff --git a/utils/utils.go b/utils/utils.go index c8cb232..ded1e35 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "fmt" + "git.rosy.net.cn/baseapi" "git.rosy.net.cn/jx-print/globals" "git.rosy.net.cn/jx-print/model" "github.com/dchest/captcha" @@ -166,3 +167,27 @@ func BuildErr(errs []error) (err error) { } return fmt.Errorf(errStr.String()) } + +func Format4Output(obj interface{}, isSingleLine bool) (retVal string) { + retVal, ok := obj.(string) + if !ok { + var ( + result []byte + err error + ) + if isSingleLine { + if result, err = json.Marshal(obj); err == nil { + retVal = string(result) + } + } else { + if result, err = json.MarshalIndent(obj, "", "\t"); err == nil { + retVal = string(result) + } + } + if err != nil { + baseapi.SugarLogger.Infof("Format4Output Marshal:%v failed with error:%v", obj, err) + retVal = fmt.Sprintf("%v", obj) + } + } + return retVal +}