This commit is contained in:
Samuel Berthe
2023-10-24 11:33:08 +02:00
parent 7b2004ad1f
commit 26cd833d20
2 changed files with 8 additions and 0 deletions
+7
View File
@@ -70,6 +70,7 @@ router := gin.New()
// Add the sloggin middleware to all routes. // Add the sloggin middleware to all routes.
// The middleware will log all requests attributes. // The middleware will log all requests attributes.
router.Use(sloggin.New(logger)) router.Use(sloggin.New(logger))
router.Use(gin.Recovery())
// Example pong request. // Example pong request.
router.GET("/pong", func(c *gin.Context) { router.GET("/pong", func(c *gin.Context) {
@@ -113,6 +114,7 @@ router.Use(
sloggin.IgnoreStatus(401, 404), sloggin.IgnoreStatus(401, 404),
), ),
) )
router.Use(gin.Recovery())
``` ```
Available filters: Available filters:
@@ -159,6 +161,7 @@ router := gin.New()
// Add the sloggin middleware to all routes. // Add the sloggin middleware to all routes.
// The middleware will log all requests attributes. // The middleware will log all requests attributes.
router.Use(sloggin.New(logger)) router.Use(sloggin.New(logger))
router.Use(gin.Recovery())
// Example pong request. // Example pong request.
router.GET("/pong", func(c *gin.Context) { router.GET("/pong", func(c *gin.Context) {
@@ -181,6 +184,7 @@ router := gin.New()
// Add the sloggin middleware to all routes. // Add the sloggin middleware to all routes.
// The middleware will log all requests attributes under a "http" group. // The middleware will log all requests attributes under a "http" group.
router.Use(sloggin.New(logger.WithGroup("http"))) router.Use(sloggin.New(logger.WithGroup("http")))
router.Use(gin.Recovery())
// Example pong request. // Example pong request.
router.GET("/pong", func(c *gin.Context) { router.GET("/pong", func(c *gin.Context) {
@@ -199,6 +203,7 @@ router.Run(":1234")
logger := slog.New(slog.NewTextHandler(os.Stdout, nil)) logger := slog.New(slog.NewTextHandler(os.Stdout, nil))
router := gin.New() router := gin.New()
router.Use(gin.Recovery())
// Example pong request. // Example pong request.
// Add the sloggin middleware to a single routes. // Add the sloggin middleware to a single routes.
@@ -226,6 +231,7 @@ router := gin.New()
// Add the sloggin middleware to all routes. // Add the sloggin middleware to all routes.
// The middleware will log all requests attributes. // The middleware will log all requests attributes.
router.Use(sloggin.New(logger)) router.Use(sloggin.New(logger))
router.Use(gin.Recovery())
// Example pong request. // Example pong request.
router.GET("/pong", func(c *gin.Context) { router.GET("/pong", func(c *gin.Context) {
@@ -250,6 +256,7 @@ router := gin.New()
// Add the sloggin middleware to all routes. // Add the sloggin middleware to all routes.
// The middleware will log all requests attributes. // The middleware will log all requests attributes.
router.Use(sloggin.New(logger)) router.Use(sloggin.New(logger))
router.Use(gin.Recovery())
// Example pong request. // Example pong request.
router.GET("/pong", func(c *gin.Context) { router.GET("/pong", func(c *gin.Context) {
+1
View File
@@ -35,6 +35,7 @@ func main() {
router.Use(sloggin.New(logger)) router.Use(sloggin.New(logger))
// config := sloggin.Config{WithRequestBody: true, WithResponseBody: true, WithRequestHeader: true, WithResponseHeader: true} // config := sloggin.Config{WithRequestBody: true, WithResponseBody: true, WithRequestHeader: true, WithResponseHeader: true}
// router.Use(sloggin.NewWithConfig(logger, config)) // router.Use(sloggin.NewWithConfig(logger, config))
router.Use(gin.Recovery())
// Example pong request. // Example pong request.
router.GET("/pong", func(c *gin.Context) { router.GET("/pong", func(c *gin.Context) {