mirror of
https://github.com/gin-gonic/gin.git
synced 2025-04-06 03:57:46 +08:00
Merge a21da9a793caa68f668f21de5ce8b7cf33495860 into 8763f33c65f7df8be5b9fe7504ab7fcf20abb41d
This commit is contained in:
commit
0989c6dd62
21
debug.go
21
debug.go
@ -22,20 +22,23 @@ func IsDebugging() bool {
|
||||
}
|
||||
|
||||
// DebugPrintRouteFunc indicates debug log output format.
|
||||
var DebugPrintRouteFunc func(httpMethod, absolutePath, handlerName string, nuHandlers int)
|
||||
var DebugPrintRouteFunc = func(httpMethod, absolutePath, handlerName string, nuHandlers int) {
|
||||
debugPrint("%-6s %-25s --> %s (%d handlers)\n", httpMethod, absolutePath, handlerName, nuHandlers)
|
||||
}
|
||||
|
||||
// DebugPrintRouteRawFunc indicates debug log output format with handlers.
|
||||
var DebugPrintRouteRawFunc = func(httpMethod, absolutePath string, handlers HandlersChain) {
|
||||
if DebugPrintRouteFunc != nil {
|
||||
DebugPrintRouteFunc(httpMethod, absolutePath, nameOfFunction(handlers.Last()), len(handlers))
|
||||
}
|
||||
}
|
||||
|
||||
// DebugPrintFunc indicates debug log output format.
|
||||
var DebugPrintFunc func(format string, values ...interface{})
|
||||
|
||||
func debugPrintRoute(httpMethod, absolutePath string, handlers HandlersChain) {
|
||||
if IsDebugging() {
|
||||
nuHandlers := len(handlers)
|
||||
handlerName := nameOfFunction(handlers.Last())
|
||||
if DebugPrintRouteFunc == nil {
|
||||
debugPrint("%-6s %-25s --> %s (%d handlers)\n", httpMethod, absolutePath, handlerName, nuHandlers)
|
||||
} else {
|
||||
DebugPrintRouteFunc(httpMethod, absolutePath, handlerName, nuHandlers)
|
||||
}
|
||||
if IsDebugging() && DebugPrintRouteRawFunc != nil {
|
||||
DebugPrintRouteRawFunc(httpMethod, absolutePath, handlers)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,6 +79,18 @@ func TestDebugPrintRouteFunc(t *testing.T) {
|
||||
assert.Regexp(t, `^\[GIN-debug\] GET /path/to/route/:param1/:param2 --> (.*/vendor/)?github.com/gin-gonic/gin.handlerNameTest \(2 handlers\)\n$`, re)
|
||||
}
|
||||
|
||||
func TestDebugPrintRouteRawFunc(t *testing.T) {
|
||||
DebugPrintRouteRawFunc = func(httpMethod, absolutePath string, handlers HandlersChain) {
|
||||
fmt.Fprintf(DefaultWriter, "[GIN-debug] %-6s %-40s --> %s (%d handlers)\n", httpMethod, absolutePath, nameOfFunction(handlers.Last()), len(handlers)+1)
|
||||
}
|
||||
re := captureOutput(t, func() {
|
||||
SetMode(DebugMode)
|
||||
debugPrintRoute("GET", "/path/to/route/:param1/:param2", HandlersChain{func(c *Context) {}, handlerNameTest})
|
||||
SetMode(TestMode)
|
||||
})
|
||||
assert.Regexp(t, `^\[GIN-debug\] GET /path/to/route/:param1/:param2 --> (.*/vendor/)?github.com/gin-gonic/gin.handlerNameTest \(3 handlers\)\n$`, re)
|
||||
}
|
||||
|
||||
func TestDebugPrintLoadTemplate(t *testing.T) {
|
||||
re := captureOutput(t, func() {
|
||||
SetMode(DebugMode)
|
||||
|
Loading…
x
Reference in New Issue
Block a user