27 lines
640 B
Go
27 lines
640 B
Go
package api
|
|
|
|
import (
|
|
"log"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func bizLog(c *gin.Context, level, module, action string, kv map[string]any) {
|
|
log.Printf("[biz][%s] request_id=%s user_id=%d module=%s action=%s kv=%v", level, requestID(c), c.GetUint("user_id"), module, action, kv)
|
|
}
|
|
|
|
func bizInfo(c *gin.Context, module, action string, kv map[string]any) {
|
|
bizLog(c, "INFO", module, action, kv)
|
|
}
|
|
|
|
func bizError(c *gin.Context, module, action, code string, err error, kv map[string]any) {
|
|
if kv == nil {
|
|
kv = map[string]any{}
|
|
}
|
|
kv["code"] = code
|
|
if err != nil {
|
|
kv["error"] = err.Error()
|
|
}
|
|
bizLog(c, "ERROR", module, action, kv)
|
|
}
|