chore(debug): add ability to override the debugPrint statement (#2337)
* 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. * chore: make the code more readable, as per review comment * fix: use tab instead of space for indentation
This commit is contained in:
parent
ac5e84d93c
commit
1b3c085969
20
debug.go
20
debug.go
@ -23,6 +23,9 @@ func IsDebugging() bool {
|
|||||||
// DebugPrintRouteFunc indicates debug log output format.
|
// DebugPrintRouteFunc indicates debug log output format.
|
||||||
var DebugPrintRouteFunc func(httpMethod, absolutePath, handlerName string, nuHandlers int)
|
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) {
|
func debugPrintRoute(httpMethod, absolutePath string, handlers HandlersChain) {
|
||||||
if IsDebugging() {
|
if IsDebugging() {
|
||||||
nuHandlers := len(handlers)
|
nuHandlers := len(handlers)
|
||||||
@ -48,12 +51,19 @@ func debugPrintLoadTemplate(tmpl *template.Template) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func debugPrint(format string, values ...any) {
|
func debugPrint(format string, values ...any) {
|
||||||
if IsDebugging() {
|
if !IsDebugging() {
|
||||||
if !strings.HasSuffix(format, "\n") {
|
return
|
||||||
format += "\n"
|
|
||||||
}
|
|
||||||
fmt.Fprintf(DefaultWriter, "[GIN-debug] "+format, values...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if DebugPrintFunc != nil {
|
||||||
|
DebugPrintFunc(format, values...)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.HasSuffix(format, "\n") {
|
||||||
|
format += "\n"
|
||||||
|
}
|
||||||
|
fmt.Fprintf(DefaultWriter, "[GIN-debug] "+format, values...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMinVer(v string) (uint64, error) {
|
func getMinVer(v string) (uint64, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user