From 814332340d39003f7a0e6032fbfc171bd1e5ce0b Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Thu, 23 Apr 2020 13:31:58 -0400 Subject: [PATCH] feat: add ability to override the debugPrint statement This allows users to use a single logger within their application for all printing, regardless of level. --- debug.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/debug.go b/debug.go index c66ca4408f..dbcd7af4aa 100644 --- a/debug.go +++ b/debug.go @@ -23,6 +23,9 @@ func IsDebugging() bool { // DebugPrintRouteFunc indicates debug log output format. var DebugPrintRouteFunc func(httpMethod, absolutePath, handlerName string, nuHandlers int) +// 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) @@ -49,10 +52,14 @@ func debugPrintLoadTemplate(tmpl *template.Template) { func debugPrint(format string, values ...interface{}) { if IsDebugging() { - if !strings.HasSuffix(format, "\n") { - format += "\n" + if DebugPrintFunc == nil { + if !strings.HasSuffix(format, "\n") { + format += "\n" + } + fmt.Fprintf(DefaultWriter, "[GIN-debug] "+format, values...) + } else { + DebugPrintFunc(format, values...) } - fmt.Fprintf(DefaultWriter, "[GIN-debug] "+format, values...) } }