debug.go 730 B

123456789101112131415161718192021222324252627282930
  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 debugRoute(httpMethod, absolutePath string, handlers []HandlerFunc) {
  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. }