Define format for the log of routes

The default log of routes is:

[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)

If you want to log this information in given format (e.g. JSON, key values or something else), then you can define this format with gin.DebugPrintRouteFunc. In the example below, we log all routes with standard log package but you can use another log tools that suits of your needs.

import (


func main() {
	r := gin.Default()
	gin.DebugPrintRouteFunc = func(httpMethod, absolutePath, handlerName string, nuHandlers int) {
		log.Printf("endpoint %v %v %v %v\n", 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
آخرین تغییرات 10.05.2024: Bump GitHub action workflows (#276) (4371021)