Commit b6be637a by yemin

调整格式化日志打印时不能反映调用者的问题

logEnd方法开放
parent a3b2e002
......@@ -38,7 +38,7 @@ func FailGetWay(c *gin.Context, state State, subCode, subMsg string) {
resp := responseSub(state, subCode, subMsg)
c.JSON(http.StatusBadGateway, resp)
c.Abort()
logEnd(c, resp)
LogEnd(c, resp)
}
func FailAndMsg(c *gin.Context, subCode, subMsg string) {
......@@ -46,7 +46,7 @@ func FailAndMsg(c *gin.Context, subCode, subMsg string) {
resp := ServerResponse{Code: BusinessError, Msg: "业务错误", SubCode: subCode, SubMsg: subMsg}
c.JSON(http.StatusOK, resp)
c.Abort()
logEnd(c, resp)
LogEnd(c, resp)
}
// FailAndMsgNoTx 不带事务
......@@ -54,7 +54,7 @@ func FailAndMsgNoTx(c *gin.Context, subCode, subMsg string) {
resp := ServerResponse{Code: BusinessError, Msg: "业务错误", SubCode: subCode, SubMsg: subMsg}
c.JSON(http.StatusOK, resp)
c.Abort()
logEnd(c, resp)
LogEnd(c, resp)
}
// Success 有事务的用这个
......@@ -63,7 +63,7 @@ func Success(c *gin.Context) {
resp := response(OK)
c.JSON(http.StatusOK, resp)
c.Abort()
logEnd(c, resp)
LogEnd(c, resp)
}
// SuccessNoTx 不带事务提交
......@@ -71,7 +71,7 @@ func SuccessNoTx(c *gin.Context) {
resp := response(OK)
c.JSON(http.StatusOK, resp)
c.Abort()
logEnd(c, resp)
LogEnd(c, resp)
}
// SuccessData 有事务的用这个
......@@ -80,7 +80,7 @@ func SuccessData(c *gin.Context, data interface{}) {
resp := ServerDataResponse{response(OK), data}
c.JSON(http.StatusOK, resp)
c.Abort()
logEnd(c, resp)
LogEnd(c, resp)
}
// SuccessDataNoTx 不带事务提交
......@@ -88,16 +88,16 @@ func SuccessDataNoTx(c *gin.Context, data interface{}) {
resp := ServerDataResponse{response(OK), data}
c.JSON(http.StatusOK, resp)
c.Abort()
logEnd(c, resp)
LogEnd(c, resp)
}
func SuccessString(c *gin.Context, data string) {
c.String(http.StatusOK, data)
c.Abort()
logEnd(c, data)
LogEnd(c, data)
}
func logEnd(c *gin.Context, data interface{}) {
func LogEnd(c *gin.Context, data interface{}) {
esSwitch := redis.SwitchOpen(redis.ES日志开关 + conf.ServerName)
startTime := GetStartTime(c)
endTime := time.Now().UnixNano()
......
......@@ -34,7 +34,16 @@ func IsDebug() bool {
}
func Debugf(format string, msg ...interface{}) {
Debug(fmt.Sprintf(format, msg...))
ok := false
switch strings.ToLower(conf.LogLevel) {
case strings.ToLower(LevelDebug):
ok = true
break
}
if ok {
_, file, line, _ := runtime.Caller(1)
print(LevelDebug, file, line, fmt.Sprintf(format, msg...))
}
}
func Debug(msg interface{}) {
......@@ -51,7 +60,19 @@ func Debug(msg interface{}) {
}
func Infof(format string, msg ...interface{}) {
Info(fmt.Sprintf(format, msg...))
ok := false
switch strings.ToLower(conf.LogLevel) {
case strings.ToLower(LevelDebug):
ok = true
break
case strings.ToLower(LevelInfo):
ok = true
break
}
if ok {
_, file, line, _ := runtime.Caller(1)
print(LevelInfo, file, line, fmt.Sprintf(format, msg...))
}
}
func Info(msg interface{}) {
......@@ -71,7 +92,22 @@ func Info(msg interface{}) {
}
func Warnf(format string, msg ...interface{}) {
Warn(fmt.Sprintf(format, msg...))
ok := false
switch strings.ToLower(conf.LogLevel) {
case strings.ToLower(LevelDebug):
ok = true
break
case strings.ToLower(LevelInfo):
ok = true
break
case strings.ToLower(LevelWarn):
ok = true
break
}
if ok {
_, file, line, _ := runtime.Caller(1)
print(LevelWarn, file, line, fmt.Sprintf(format, msg...))
}
}
func Warn(msg interface{}) {
......@@ -89,12 +125,30 @@ func Warn(msg interface{}) {
}
if ok {
_, file, line, _ := runtime.Caller(1)
print(LevelWarn,file, line, msg)
print(LevelWarn, file, line, msg)
}
}
func Errorf(format string, msg ...interface{}) {
Error(fmt.Sprintf(format, msg...))
ok := false
switch strings.ToLower(conf.LogLevel) {
case strings.ToLower(LevelDebug):
ok = true
break
case strings.ToLower(LevelInfo):
ok = true
break
case strings.ToLower(LevelWarn):
ok = true
break
case strings.ToLower(LevelError):
ok = true
break
}
if ok {
_, file, line, _ := runtime.Caller(1)
print(LevelError, file, line, fmt.Sprintf(format, msg...))
}
}
func Error(msg interface{}) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment