mirror of
				https://github.com/steveiliop56/tinyauth.git
				synced 2025-10-31 06:05:43 +00:00 
			
		
		
		
	feat: better health check and less log noise (#274)
* feat: better health check and less log noise * feat: better health check and less log noise
This commit is contained in:
		| @@ -21,6 +21,23 @@ type Server struct { | |||||||
| 	Router   *gin.Engine | 	Router   *gin.Engine | ||||||
| } | } | ||||||
|  |  | ||||||
|  | var ( | ||||||
|  | 	loggerSkipPathsPrefix = []string{ | ||||||
|  | 		"GET /api/healthcheck",  | ||||||
|  | 		"HEAD /api/healthcheck",  | ||||||
|  | 		"GET /favicon.ico", | ||||||
|  | 	} | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | func logPath(path string) bool{ | ||||||
|  | 	for _, prefix := range loggerSkipPathsPrefix { | ||||||
|  | 		if strings.HasPrefix(path, prefix) { | ||||||
|  | 			return false | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	return true | ||||||
|  | } | ||||||
|  |  | ||||||
| func NewServer(config types.ServerConfig, handlers *handlers.Handlers) (*Server, error) { | func NewServer(config types.ServerConfig, handlers *handlers.Handlers) (*Server, error) { | ||||||
| 	gin.SetMode(gin.ReleaseMode) | 	gin.SetMode(gin.ReleaseMode) | ||||||
|  |  | ||||||
| @@ -68,6 +85,7 @@ func NewServer(config types.ServerConfig, handlers *handlers.Handlers) (*Server, | |||||||
|  |  | ||||||
| 	// App routes | 	// App routes | ||||||
| 	router.GET("/api/healthcheck", handlers.HealthcheckHandler) | 	router.GET("/api/healthcheck", handlers.HealthcheckHandler) | ||||||
|  | 	router.HEAD("/api/healthcheck", handlers.HealthcheckHandler) | ||||||
|  |  | ||||||
| 	return &Server{ | 	return &Server{ | ||||||
| 		Config:   config, | 		Config:   config, | ||||||
| @@ -100,6 +118,7 @@ func zerolog() gin.HandlerFunc { | |||||||
| 		latency := time.Since(tStart).String() | 		latency := time.Since(tStart).String() | ||||||
|  |  | ||||||
| 		// Log request | 		// Log request | ||||||
|  | 		if logPath(method + " " + path) { | ||||||
| 			switch { | 			switch { | ||||||
| 				case code >= 200 && code < 300: | 				case code >= 200 && code < 300: | ||||||
| 					log.Info().Str("method", method).Str("path", path).Str("address", address).Int("status", code).Str("latency", latency).Msg("Request") | 					log.Info().Str("method", method).Str("path", path).Str("address", address).Int("status", code).Str("latency", latency).Msg("Request") | ||||||
| @@ -108,5 +127,8 @@ func zerolog() gin.HandlerFunc { | |||||||
| 				case code >= 400: | 				case code >= 400: | ||||||
| 					log.Error().Str("method", method).Str("path", path).Str("address", address).Int("status", code).Str("latency", latency).Msg("Request") | 					log.Error().Str("method", method).Str("path", path).Str("address", address).Int("status", code).Str("latency", latency).Msg("Request") | ||||||
| 			} | 			} | ||||||
|  | 		}else{ | ||||||
|  | 			log.Debug().Str("method", method).Str("path", path).Str("address", address).Int("status", code).Str("latency", latency).Msg("Request") | ||||||
|  | 		}		 | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
		Reference in New Issue
	
	Block a user
	 ElevenNotes
					ElevenNotes