refactor🎨: 操作log添加字符限制
This commit is contained in:
1 parent
c1347fbb5d
commit
3f90605589
3 files changed
+14
-10
No files matched your search
@@ -74,6 +74,10 @@ func SaveOperaLog(message storage.Messager) (err error) {
|
||||
// Log writing to the database ignores error
|
||||
return nil
|
||||
}
|
||||
// 超出100个字符返回值截断
|
||||
if len(l.JsonResult) > 100 {
|
||||
l.JsonResult = l.JsonResult[:100]
|
||||
}
|
||||
err = db.Create(&l).Error
|
||||
if err != nil {
|
||||
log.Errorf("db create error, %s", err.Error())
|
||||
|
||||
@@ -23,6 +23,5 @@ func GetClientIP(c *gin.Context) string {
|
||||
if ClientIP != "127.0.0.1" {
|
||||
ip = ClientIP
|
||||
}
|
||||
//fmt.Println("ip:", ip)
|
||||
return ip
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package middleware
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"go-admin/common"
|
||||
gaConfig "go-admin/config"
|
||||
@@ -56,16 +57,16 @@ func LoggerToFile() gin.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
//rt, bl := c.Get("result")
|
||||
rt, bl := c.Get("result")
|
||||
var result = ""
|
||||
//if bl {
|
||||
// rb, err := json.Marshal(rt)
|
||||
// if err != nil {
|
||||
// log.Warnf("json Marshal result error, %s", err.Error())
|
||||
// } else {
|
||||
// result = string(rb)
|
||||
// }
|
||||
//}
|
||||
if bl {
|
||||
rb, err := json.Marshal(rt)
|
||||
if err != nil {
|
||||
log.Warnf("json Marshal result error, %s", err.Error())
|
||||
} else {
|
||||
result = string(rb)
|
||||
}
|
||||
}
|
||||
|
||||
st, bl := c.Get("status")
|
||||
var statusBus = 0
|
||||
|
||||
Reference in new issue
Block a user