debug.go
This file
Path
debug.go
103 lines · 2.7 KiB · Go
Last changed by
Make sure the debug log contains line breaks (#1650)henrylee2cnbefore adoption3d44ff8
History of this fileTake it
The walk stopped after 200 commits: lines older than bbd4dfe point at it.
add warning using http2 example (#1009)田欧before adoptionbbd4dfe
lines 1–8why, one step back1// Copyright 2014 Manu Martinez-Almeida. All rights reserved.2// Use of this source code is governed by a MIT style3// license that can be found in the LICENSE file.45package gin67import (8 "bytes"feat: replace debug log with fmt package. (#1560)Bo-Yi Wubefore adoption07f1bf0
line 9why, one step back9 "fmt"add warning using http2 example (#1009)田欧before adoptionbbd4dfe
line 10why, one step back10 "html/template"fix: fmt output log to os.Stderr (#1571)Bo-Yi Wubefore adoption402ef12
line 11why, one step back11 "os"feat: add go version judge when print debug warning log (#1572)田欧before adoption834a2ec
lines 12–14why, one step back12 "runtime"13 "strconv"14 "strings"add warning using http2 example (#1009)田欧before adoptionbbd4dfe
lines 15–16why, one step back15)16feat: add go version judge when print debug warning log (#1572)田欧before adoption834a2ec
lines 17–18why, one step back17const ginSupportMinGoVer = 618add warning using http2 example (#1009)田欧before adoptionbbd4dfe
line 19why, one step back19// IsDebugging returns true if the framework is running in debug mode.Update comment to reflect correct constant. (#1144)Mike Stipicevicbefore adoption76ad15a
line 20why, one step back20// Use SetMode(gin.ReleaseMode) to disable debug mode.add warning using http2 example (#1009)田欧before adoptionbbd4dfe
lines 21–24why, one step back21func IsDebugging() bool {22 return ginMode == debugCode23}24chore: fix typo and add a little anotation (#1562)田欧before adoptionf2cd3fc
line 25why, one step back25// DebugPrintRouteFunc indicates debug log output format.Let's user define how he wants to log his routes (eg. JSON, key value, or something else) (#1553) (#1555)Jérôme Laforgebefore adoption90c680e
lines 26–27why, one step back26var DebugPrintRouteFunc func(httpMethod, absolutePath, handlerName string, nuHandlers int)27add warning using http2 example (#1009)田欧before adoptionbbd4dfe
lines 28–31why, one step back28func debugPrintRoute(httpMethod, absolutePath string, handlers HandlersChain) {29 if IsDebugging() {30 nuHandlers := len(handlers)31 handlerName := nameOfFunction(handlers.Last())Let's user define how he wants to log his routes (eg. JSON, key value, or something else) (#1553) (#1555)Jérôme Laforgebefore adoption90c680e
lines 32–36why, one step back32 if DebugPrintRouteFunc == nil {33 debugPrint("%-6s %-25s --> %s (%d handlers)\n", httpMethod, absolutePath, handlerName, nuHandlers)34 } else {35 DebugPrintRouteFunc(httpMethod, absolutePath, handlerName, nuHandlers)36 }add warning using http2 example (#1009)田欧before adoptionbbd4dfe
lines 37–53why, one step back37 }38}3940func debugPrintLoadTemplate(tmpl *template.Template) {41 if IsDebugging() {42 var buf bytes.Buffer43 for _, tmpl := range tmpl.Templates() {44 buf.WriteString("\t- ")45 buf.WriteString(tmpl.Name())46 buf.WriteString("\n")47 }48 debugPrint("Loaded HTML Templates (%d): \n%s\n", len(tmpl.Templates()), buf.String())49 }50}5152func debugPrint(format string, values ...interface{}) {53 if IsDebugging() {Make sure the debug log contains line breaks (#1650)henrylee2cnbefore adoption3d44ff8
lines 54–56why, one step back54 if !strings.HasSuffix(format, "\n") {55 format += "\n"56 }fix: fmt output log to os.Stderr (#1571)Bo-Yi Wubefore adoption402ef12
line 57why, one step back57 fmt.Fprintf(os.Stderr, "[GIN-debug] "+format, values...)add warning using http2 example (#1009)田欧before adoptionbbd4dfe
lines 58–60why, one step back58 }59}60feat: add go version judge when print debug warning log (#1572)田欧before adoption834a2ec
lines 61–69why, one step back61func getMinVer(v string) (uint64, error) {62 first := strings.IndexByte(v, '.')63 last := strings.LastIndexByte(v, '.')64 if first == last {65 return strconv.ParseUint(v[first+1:], 10, 64)66 }67 return strconv.ParseUint(v[first+1:last], 10, 64)68}69Print warning log when user create one engine using gin.Default in debug mode (#1121)田欧before adoption0cb7c44
line 70why, one step back70func debugPrintWARNINGDefault() {feat: add go version judge when print debug warning log (#1572)田欧before adoption834a2ec
lines 71–72why, one step back71 if v, e := getMinVer(runtime.Version()); e == nil && v <= ginSupportMinGoVer {72 debugPrint(`[WARNING] Now Gin requires Go 1.6 or later and Go 1.7 will be required soon.add go version prerequisite and debug warning (#1394)田欧before adoptionc00f21f
lines 73–74why, one step back7374`)feat: add go version judge when print debug warning log (#1572)田欧before adoption834a2ec
line 75why, one step back75 }Print warning log when user create one engine using gin.Default in debug mode (#1121)田欧before adoption0cb7c44
lines 76–80why, one step back76 debugPrint(`[WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.7778`)79}80add warning using http2 example (#1009)田欧before adoptionbbd4dfe
lines 81–103why, one step back81func debugPrintWARNINGNew() {82 debugPrint(`[WARNING] Running in "debug" mode. Switch to "release" mode in production.83 - using env: export GIN_MODE=release84 - using code: gin.SetMode(gin.ReleaseMode)8586`)87}8889func debugPrintWARNINGSetHTMLTemplate() {90 debugPrint(`[WARNING] Since SetHTMLTemplate() is NOT thread-safe. It should only be called91at initialization. ie. before any route is registered or the router is listening in a socket:9293 router := gin.Default()94 router.SetHTMLTemplate(template) // << good place9596`)97}9899func debugPrintError(err error) {100 if err != nil {101 debugPrint("[ERROR] %v\n", err)102 }103}