zoukankan      html  css  js  c++  java
  • 自定义路由日志的格式

    默认的路由日志是这样的:

    [GIN-debug] POST   /foo                      --> main.main.func1 (3 handlers)
    [GIN-debug] GET    /bar                      --> main.main.func2 (3 handlers)
    [GIN-debug] GET    /status                   --> main.main.func3 (3 handlers)
    

    如果你想以给定的格式记录这些信息(例如 JSON,键值对或其他格式),你可以使用gin.DebugPrintRouteFunc来定义格式,在下面的示例中,我们使用标准日志包记录路由日志,你可以使用其他适合你需求的日志工具

    import (
    	"log"
    	"net/http"
    
    	"github.com/gin-gonic/gin"
    )
    
    func main() {
    	r := gin.Default()
    	gin.DebugPrintRouteFunc = func(httpMethod, absolutePath, handlerName string, nuHandlers int) {
    		log.Printf("endpoint %v %v %v %v
    ", httpMethod, absolutePath, handlerName, nuHandlers)
    	}
    
    	r.POST("/foo", func(c *gin.Context) {
    		c.JSON(http.StatusOK, "foo")
    	})
    
    	r.GET("/bar", func(c *gin.Context) {
    		c.JSON(http.StatusOK, "bar")
    	})
    
    	r.GET("/status", func(c *gin.Context) {
    		c.JSON(http.StatusOK, "ok")
    	})
    
    	// Listen and Server in http://0.0.0.0:8080
    	r.Run()
    }
    

      

  • 相关阅读:
    Pytorch 入门之Siamese网络
    Pytorch 之 backward
    非极大值抑制(NMS)
    Apriori 算法python实现
    canny 算子python实现
    转载
    ubuntu 安装lightgbm
    OneHotEncoder独热编码和 LabelEncoder标签编码
    Adroid—— DVM
    PHP——做服务
  • 原文地址:https://www.cnblogs.com/yzg-14/p/13153443.html
Copyright © 2011-2022 走看看