Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable warning for debug mode #1346

Closed
zwhitchcox opened this issue May 4, 2018 · 7 comments
Closed

Disable warning for debug mode #1346

zwhitchcox opened this issue May 4, 2018 · 7 comments
Labels

Comments

@zwhitchcox
Copy link

I'm trying to develop using Gin, and I keep getting this warning

[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production

I don't care, and it is cluttering up my log, so I can't see the real errors. Is there a way to disable this "feature"?

@thinkerou
Copy link
Member

It tell us: now debug mode and how switch release mode.

[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)

@zwhitchcox
Copy link
Author

Yeah, but you pretty much know when you're in debug mode, and you can google how to get to production mode. It is one more garbage thing you have to ignore when you're developing. At least make it an option to disable it.

@delphinus
Copy link

delphinus commented May 6, 2018

It is just as the option to suppress debugging logs -- gin.SetMode(gin.ReleaseMode). You can use this to ignore logs.

Or you just grep -v to ignore specific ones.

go run /tmp/test.go 2>&1 | egrep -v 'Running in "debug" mode|using (env|code)'

gin shows various debugging logs and it is not good to add an option to ignore each log individually...

@fwhezfwhez
Copy link

if you want to close tips of debug warning ,use this in your beginning

gin.SetMode(gin.ReleaseMode)

if you want to close logger middleware ,example :
[GIN] 2018/05/08 - 18:38:00 | 200 | 25.0676ms | x.x.x.x | GET xxxxx/xxxx/xxx
use below to init a router:

router := gin.New()
router.Use(gin.Recovery())

@rdnt
Copy link

rdnt commented Nov 13, 2019

You can suppress the debug warning by overwriting the os.Stderr file descriptor temporarily before starting Gin, and then restoring it:

stderr := os.Stderr
fd, _ := os.Open(os.DevNull)
os.Stderr = fd

r := gin.New()

os.Stderr = stderr

This will redirect Gin's debug mode message to /dev/null, essentially discarding it.
Warning: If Gin fails to create an engine, the errors will not be shown. Use this at your own risk.

@rdnt
Copy link

rdnt commented Nov 28, 2019

Fixed in #1891 (gin 1.5.0)

@danielkurniadi
Copy link

Might be a side feature which unlikely to go through but I wonder if instead of:

I'm trying to develop using Gin, and I keep getting this warning

[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production
I don't care, and it is cluttering up my log, so I can't see the real errors. Is there a way to disable this "feature"?

We can just log this warning once through out one application lifecycle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants