diff --git a/debug.go b/debug.go index f2016168..0fcb29bd 100644 --- a/debug.go +++ b/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) } } diff --git a/debug_test.go b/debug_test.go index 59b61beb..3765e45b 100644 --- a/debug_test.go +++ b/debug_test.go @@ -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)