2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Ginで特定のパスの場合にログを出さない方法

Posted at

gin.Default() を利用していると

func Default() *Engine {
	debugPrintWARNINGDefault()
	engine := New()
	engine.Use(Logger(), Recovery())
	return engine
}

のように gin.Logger() gin.Recovery()
が適用されてしまう。
ここで適用されているgin.Loggerは設定が変更できないので
gin.New() を利用して

r := gin.New()
r.Use(gin.LoggerWithConfig(gin.LoggerConfig{SkipPaths: []string{"/healthcheck"}}))
r.Use(gin.Recovery())

のように手動で設定しgin.LoggerConfigにSkipPathsを設定する
gin.Recovery()の設定を忘れると500エラーを吐いた場合にginが落ちてしまうので注意!

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?