gin
gin copied to clipboard
gin.setMode release effect,but console still output run on debug mode
- With issues:
- Use the search tool before opening a new issue.
- Please provide source code and commit sha if you found a bug.
- Review existing issues and provide feedback or react to them.
Description
gin.setMode release effect,but console still output run on debug mode
How to reproduce
gin.SetMode(gin.ReleaseMode)
if gin.Mode() == gin.ReleaseMode {
f, _ := os.Create(cfg.Section("log").Key("path").String())
gin.DefaultWriter = io.MultiWriter(f)
}
routes.Run(cfg.Section("httpserver").Key("port").String())
Expectations
[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
- using env: export GIN_MODE=release
- using code: gin.SetMode(gin.ReleaseMode)
Actual result
[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
- using env: export GIN_MODE=release
- using code: gin.SetMode(gin.ReleaseMode)
## Environment
- go version:1.19
- gin version (or commit ref):1.8.1
- operating system:windows10
in order to set env variable in windows you have to use set
:
set GIN_MODE="release"
https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/set_1
@Gasoid why?
in order to set env variable in windows you have to use set:
why doesn't work as code on windows?
according to code https://github.com/gin-gonic/gin/blob/2ae61570499d8bb5eb05e46d22a3754cf2635e63/mode.go#L57-L78
it is pretty straightforward. Do you have full context of your code ? before gin.SetMode(gin.ReleaseMode)
in order to set env variable in windows you have to use
set
:set GIN_MODE="release"
https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/set_1
-
cmd
set GIN_MODE=release
No quotes
-
PowerShell
$env:GIN_MODE="release"
Need quotes
my os is ubuntu 20 and I have the same problem , here is my code:
gin.SetMode(gin.ReleaseMode)
gin.DefaultWriter = io.Discard
router := routers.InitRouter()
fmt.Println("gin.IsDebugging() : ", gin.IsDebugging())
server := &http.Server{
Addr: "0.0.0.0:8010",
Handler: router,
}
// log.Printf("[info] start http server listening %s", endpoint)
err := server.ListenAndServe()
if err != nil {
log.Fatal("fatal error in serve http : ", err.Error())
}
and then output :
[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
- using env: export GIN_MODE=release
- using code: gin.SetMode(gin.ReleaseMode)
gin.IsDebugging() : false
go : 1.20 gin : 1.9.0
does anyone notice?
I found the problem My mistake is an extra gin.New() was in other files that I forgot to remove and caused this warning.