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.
This commit is contained in:
Jose Diaz-Gonzalez 2020-04-23 13:31:58 -04:00 committed by GitHub
parent be4ba7d9df
commit 814332340d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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...)
}
}