提交 6612e792 编写于 作者: Mr.奇淼('s avatar Mr.奇淼(

开启日志功能

上级 844c63ac
......@@ -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,
......
......@@ -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) // 注册用户路由
......
......@@ -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
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册