debug.go 941 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright 2014 Manu Martinez-Almeida. All rights reserved.
  2. // Use of this source code is governed by a MIT style
  3. // license that can be found in the LICENSE file.
  4. package gin
  5. import (
  6. "log"
  7. "os"
  8. )
  9. var debugLogger = log.New(os.Stdout, "[GIN-debug] ", 0)
  10. func IsDebugging() bool {
  11. return ginMode == debugCode
  12. }
  13. func debugPrintRoute(httpMethod, absolutePath string, handlers HandlersChain) {
  14. if IsDebugging() {
  15. nuHandlers := len(handlers)
  16. handlerName := nameOfFunction(handlers[nuHandlers-1])
  17. debugPrint("%-5s %-25s --> %s (%d handlers)\n", httpMethod, absolutePath, handlerName, nuHandlers)
  18. }
  19. }
  20. func debugPrint(format string, values ...interface{}) {
  21. if IsDebugging() {
  22. debugLogger.Printf(format, values...)
  23. }
  24. }
  25. func debugPrintWARNING() {
  26. debugPrint("[WARNING] Running in DEBUG mode! Disable it before going production\n")
  27. }
  28. func debugPrintError(err error) {
  29. if err != nil {
  30. debugPrint("[ERROR] %v\n", err)
  31. }
  32. }