Skip to content

✨ v3 (feature): refactor logger middleware#1979

Merged
ReneWerner87 merged 7 commits intov3-betafrom
v3-refactor-logger
Sep 5, 2022
Merged

✨ v3 (feature): refactor logger middleware#1979
ReneWerner87 merged 7 commits intov3-betafrom
v3-refactor-logger

Conversation

@efectn
Copy link
Member

@efectn efectn commented Jul 18, 2022

- Make middleware extandable for 3rd-party loggers. (#1828)
@efectn efectn added this to the v3 milestone Jul 18, 2022
@efectn efectn requested a review from ReneWerner87 July 18, 2022 19:26
- Make middleware extandable for 3rd-party loggers. (#1828)
@YuilTripathee
Copy link
Contributor

What is the point of keeping the existing logger function in a new default_logger way? Is there example for which other custom logger is possible to call from this by this approach?

@efectn
Copy link
Member Author

efectn commented Jul 31, 2022

What is the point of keeping the existing logger function in a new default_logger way? Is there example for which other custom logger is possible to call from this by this approach?

Zerolog example:

package main

import (
	"os"

	"github.com/gofiber/fiber/v3"
	"github.com/gofiber/fiber/v3/middleware/logger"
	"github.com/rs/zerolog"
	"github.com/rs/zerolog/log"
)

func main() {
	app := fiber.New()

	log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})

	app.Use(logger.New(logger.Config{LoggerFunc: func(c fiber.Ctx, data logger.LoggerData, cfg logger.Config) error {
		log.Info().
			Str("path", c.Path()).
			Str("method", c.Method()).
			Int("status", c.Response().
				StatusCode()).
			Msg("new request")

		return nil
	}}))

	app.Get("/", func(c fiber.Ctx) error {
		return c.SendString("test")
	})

	app.Listen(":3000")
}

Copy link
Contributor

@YuilTripathee YuilTripathee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need some work on benchmarks to proceed

@ReneWerner87 ReneWerner87 merged commit 154e4f8 into v3-beta Sep 5, 2022
@efectn efectn deleted the v3-refactor-logger branch September 5, 2022 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants