debug.go 1002 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 "log"
  6. func init() {
  7. log.SetFlags(0)
  8. }
  9. func IsDebugging() bool {
  10. return ginMode == debugCode
  11. }
  12. func debugPrintRoute(httpMethod, absolutePath string, handlers HandlersChain) {
  13. if IsDebugging() {
  14. nuHandlers := len(handlers)
  15. handlerName := nameOfFunction(handlers[nuHandlers-1])
  16. debugPrint("%-5s %-25s --> %s (%d handlers)\n", httpMethod, absolutePath, handlerName, nuHandlers)
  17. }
  18. }
  19. func debugPrint(format string, values ...interface{}) {
  20. if IsDebugging() {
  21. log.Printf("[GIN-debug] "+format, values...)
  22. }
  23. }
  24. func debugPrintWARNING() {
  25. debugPrint(`[WARNING] Running in "debug" mode. Switch to "release" mode in production.
  26. - using env: export GIN_MODE=release
  27. - using code: gin.SetMode(gin.ReleaseMode)
  28. `)
  29. }
  30. func debugPrintError(err error) {
  31. if err != nil {
  32. debugPrint("[ERROR] %v\n", err)
  33. }
  34. }