feat : Log optimization
This commit is contained in:
1 parent
f3a425a82b
commit
22124b236a
4 files changed
+36
-10
No files matched your search
@@ -4,6 +4,7 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
"github.com/google/uuid"
|
||||
"go-admin/global"
|
||||
"go-admin/models"
|
||||
"go-admin/tools"
|
||||
"go-admin/tools/app"
|
||||
@@ -209,7 +210,7 @@ func InsetSysUserAvatar(c *gin.Context) {
|
||||
guid := uuid.New().String()
|
||||
filPath := "static/uploadfile/" + guid + ".jpg"
|
||||
for _, file := range files {
|
||||
tools.Logger.Println(file.Filename)
|
||||
global.Logger.Debug(file.Filename)
|
||||
// 上传文件至指定目录
|
||||
_ = c.SaveUploadedFile(file, filPath)
|
||||
}
|
||||
|
||||
+5
-4
@@ -3,6 +3,7 @@ package tools
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go-admin/global"
|
||||
"go-admin/models"
|
||||
"go-admin/models/tools"
|
||||
tools2 "go-admin/tools"
|
||||
@@ -116,17 +117,17 @@ func GenCode(c *gin.Context) {
|
||||
NewText: newText,
|
||||
}
|
||||
if helper.OldText == helper.NewText {
|
||||
tools2.Logger.Println("error !! the NewText isEqual the OldText")
|
||||
global.Logger.Println("error !! the NewText isEqual the OldText")
|
||||
return
|
||||
}
|
||||
if err := helper.DoWrok(); err != nil {
|
||||
tools2.Logger.Print("error:", err.Error())
|
||||
global.Logger.Print("error:", err.Error())
|
||||
|
||||
} else {
|
||||
tools2.Logger.Print("done!")
|
||||
global.Logger.Print("done!")
|
||||
}
|
||||
|
||||
app.OK(c, "", "代码生成成功!")
|
||||
app.OK(c, "", "Code generated successfully!")
|
||||
}
|
||||
|
||||
func GenMenuAndApi(c *gin.Context) {
|
||||
|
||||
+2
-2
@@ -88,14 +88,14 @@ func Authenticator(c *gin.Context) (interface{}, error) {
|
||||
msg = "登录失败"
|
||||
status = "1"
|
||||
LoginLogToDB(c, status, msg, username)
|
||||
global.AccessLogger.Println(e.Error())
|
||||
global.RequestLogger.Println(e.Error())
|
||||
}
|
||||
return nil, jwt.ErrFailedAuthentication
|
||||
}
|
||||
|
||||
// Write log to database
|
||||
func LoginLogToDB(c *gin.Context, status string, msg string, username string) {
|
||||
if config.LoggerConfig.Enabled {
|
||||
if config.LoggerConfig.EnabledDB {
|
||||
var loginlog models.LoginLog
|
||||
ua := user_agent.New(c.Request.UserAgent())
|
||||
loginlog.Ipaddr = c.ClientIP()
|
||||
|
||||
+27
-3
@@ -2,14 +2,38 @@ package logger
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/os/glog"
|
||||
"go-admin/global"
|
||||
"go-admin/tools"
|
||||
"go-admin/tools/config"
|
||||
)
|
||||
|
||||
var Logger *glog.Logger
|
||||
var DBLogger *glog.Logger
|
||||
var RequestLogger *glog.Logger
|
||||
|
||||
func InitLog() {
|
||||
func Setup() {
|
||||
Logger = glog.New()
|
||||
Logger.Path(config.LoggerConfig.Path)
|
||||
Logger.SetPath(config.LoggerConfig.Path + "/bus")
|
||||
Logger.SetStdoutPrint(config.LoggerConfig.EnabledBUS)
|
||||
Logger.SetFile("logger-{Ymd}.log")
|
||||
_ = Logger.SetLevelStr(config.LoggerConfig.Level)
|
||||
Logger.Info("Logger init Success!")
|
||||
|
||||
DBLogger = glog.New()
|
||||
_ = DBLogger.SetPath(config.LoggerConfig.Path + "/db")
|
||||
DBLogger.SetStdoutPrint(false)
|
||||
DBLogger.SetFile("db-{Ymd}.log")
|
||||
_ = DBLogger.SetLevelStr(config.LoggerConfig.Level)
|
||||
|
||||
RequestLogger = glog.New()
|
||||
_ = RequestLogger.SetPath(config.LoggerConfig.Path + "/request")
|
||||
RequestLogger.SetStdoutPrint(false)
|
||||
RequestLogger.SetFile("access-{Ymd}.log")
|
||||
_ = RequestLogger.SetLevelStr(config.LoggerConfig.Level)
|
||||
|
||||
|
||||
Logger.Info(tools.Green("Logger init success!"))
|
||||
|
||||
global.Logger = Logger.Line()
|
||||
global.DBLogger = DBLogger.Line()
|
||||
global.RequestLogger = RequestLogger.Line()
|
||||
}
|
||||
Reference in new issue
Block a user