feat: cleanup calling of debuglogger with managed debug setting

This commit is contained in:
Ben McClelland
2025-05-02 17:05:59 -07:00
parent d19c446f72
commit a9fcf63063
7 changed files with 91 additions and 127 deletions
+11
View File
@@ -19,6 +19,7 @@ import (
"log"
"net/http"
"strings"
"sync/atomic"
"github.com/gofiber/fiber/v2"
)
@@ -81,9 +82,19 @@ func LogFiberResponseDetails(ctx *fiber.Ctx) {
}
}
var debugEnabled atomic.Bool
// SetDebugEnabled sets the debug mode
func SetDebugEnabled() {
debugEnabled.Store(true)
}
// Logf is the same as 'fmt.Printf' with debug prefix,
// a color added and '\n' at the end
func Logf(format string, v ...any) {
if !debugEnabled.Load() {
return
}
debugPrefix := "[DEBUG]: "
fmt.Printf(yellow+debugPrefix+format+reset+"\n", v...)
}