gin/debug.go

43 lines
1002 B
Go
Raw Normal View History

2015-03-23 08:03:12 +03:00
// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package gin
import "log"
2015-03-23 08:03:12 +03:00
func init() {
log.SetFlags(0)
}
2015-03-23 08:03:12 +03:00
func IsDebugging() bool {
2015-04-07 13:27:23 +03:00
return ginMode == debugCode
2015-03-23 08:03:12 +03:00
}
2015-05-09 04:34:43 +03:00
func debugPrintRoute(httpMethod, absolutePath string, handlers HandlersChain) {
2015-03-23 08:03:12 +03:00
if IsDebugging() {
nuHandlers := len(handlers)
handlerName := nameOfFunction(handlers[nuHandlers-1])
debugPrint("%-5s %-25s --> %s (%d handlers)\n", httpMethod, absolutePath, handlerName, nuHandlers)
}
}
func debugPrint(format string, values ...interface{}) {
if IsDebugging() {
log.Printf("[GIN-debug] "+format, values...)
2015-03-23 08:03:12 +03:00
}
}
2015-05-09 04:34:43 +03:00
func debugPrintWARNING() {
2015-05-24 02:21:23 +03:00
debugPrint(`[WARNING] Running in "debug" mode. Switch to "release" mode in production.
- using env: export GIN_MODE=release
- using code: gin.SetMode(gin.ReleaseMode)
`)
2015-05-09 04:34:43 +03:00
}
func debugPrintError(err error) {
if err != nil {
debugPrint("[ERROR] %v\n", err)
}
}