Skip to content

Commit

Permalink
feat: add ability to override the debugPrint statement
Browse files Browse the repository at this point in the history
This allows users to use a single logger within their application for all printing, regardless of level.
  • Loading branch information
josegonzalez authored Apr 23, 2020
1 parent be4ba7d commit 8143323
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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...)
}
}

Expand Down

0 comments on commit 8143323

Please sign in to comment.