diff --git a/QMPlusServer/controller/servers/reportformat.go b/QMPlusServer/controller/servers/reportformat.go index 2b935fea5d239772f111c03c8b820132fc941995..a28c0fb262069e15edbeee83c63ddffd51e26b7b 100644 --- a/QMPlusServer/controller/servers/reportformat.go +++ b/QMPlusServer/controller/servers/reportformat.go @@ -2,10 +2,28 @@ package servers import ( "github.com/gin-gonic/gin" + "main/init/qmlog" "net/http" + "time" ) func ReportFormat(c *gin.Context, success bool, msg string, json gin.H) { + // 开始时间 + start := time.Now() + path := c.Request.URL.Path + clientIP := c.ClientIP() + method := c.Request.Method + statusCode := c.Writer.Status() + qmlog.QMLog.Infof("| %3d | %13v | %15s | %s %s |%s|", + statusCode, + start, + clientIP, + method, path, gin.H{ + "success": success, + "msg": msg, + "data": json, + }, + ) c.JSON(http.StatusOK, gin.H{ "success": success, "msg": msg, diff --git a/QMPlusServer/init/initRouter/initRouter.go b/QMPlusServer/init/initRouter/initRouter.go index bac9e650ea89082e75f7f4374887471b024057fc..fd3ba87487442b515ced437921867984971978a2 100644 --- a/QMPlusServer/init/initRouter/initRouter.go +++ b/QMPlusServer/init/initRouter/initRouter.go @@ -5,12 +5,14 @@ import ( "github.com/swaggo/gin-swagger" "github.com/swaggo/gin-swagger/swaggerFiles" _ "main/docs" + "main/middleware" "main/router" ) //初始化总路由 func InitRouter() *gin.Engine { var Router = gin.Default() + Router.Use(middleware.Logger()) // 如果不需要日志 请关闭这里 Router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) //Router.Use(middleware.Logger()) router.InitUserRouter(Router) // 注册用户路由 diff --git a/QMPlusServer/main.go b/QMPlusServer/main.go index e40d290f7b3ab41f5135cfd7671df8ffc28e75b4..7d3f0f0d222d33736138a3494deea69d507ed598 100644 --- a/QMPlusServer/main.go +++ b/QMPlusServer/main.go @@ -23,7 +23,7 @@ func main() { registTable.RegistTable(qmsql.InitMysql(config.Dbconfig.Admin)) defer qmsql.DEFAULTDB.Close() Router := initRouter.InitRouter() - //qmlog.QMLog.Info("服务器开启") // 日志测试代码 + qmlog.QMLog.Info("服务器开启") // 日志测试代码 s := &http.Server{ Addr: ":8888", @@ -32,16 +32,16 @@ func main() { WriteTimeout: 10 * time.Second, MaxHeaderBytes: 1 << 20, } - time.Sleep(10*time.Microsecond) + time.Sleep(10 * time.Microsecond) fmt.Printf(`欢迎使用 Gin-Vue-Admin 作者:奇淼 And Spike666 微信:shouzi_1994 默认自动化文档地址:http://127.0.0.1%s/swagger/index.html 默认前端文件运行地址:http://127.0.0.1:8080 -`,s.Addr) +`, s.Addr) _ = s.ListenAndServe() } -func run(server *http.Server){ +func run(server *http.Server) { -} \ No newline at end of file +}