gofiber / fiber

⚡️ Express inspired web framework written in Go
https://gofiber.io
MIT License
33.86k stars 1.66k forks source link

🚀 [Feature]: middleware/logger: use Logger interface #2737

Open folliehiyuki opened 11 months ago

folliehiyuki commented 11 months ago

Feature Description

With the introduction of Logger interface (https://github.com/gofiber/fiber/pull/2499), it is easier now to plug my own log library into Fiber. With that said, logger middleware still uses fmt.Sprintf().

It would be nice if logger middleware is extended to accept logging via Logger interface. This creates an easier method to have structure log for requests/responses without the need of making a custom external middleware. Judging from https://github.com/gofiber/fiber/issues/1293#issuecomment-829210674, if we want to keep the current logger middleware as simple as it is, making a new logger middleware would also be reasonable.

Additional Context (optional)

No response

Code Snippet (optional)

No response

Checklist:

welcome[bot] commented 11 months ago

Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

efectn commented 11 months ago

Hi. Can you provide a proof-of-concept? If we can do it without breaking something on v2, it's OK to me. Otherwise, we have to adjust logger middleware on v3.

ReneWerner87 commented 11 months ago

@FollieHiyuki

folliehiyuki commented 11 months ago

Can you provide a proof-of-concept? If we can do it without breaking something on v2, it's OK to me

I don't have a concrete idea how to do this cleanly right now.

Otherwise, we have to adjust logger middleware on v3.

That sounds reasonable to me. It's nothing urgent (at least for me) and also takes less effort (no need to keep the compatibility with the current template interface).

haochunchang commented 1 month ago

Hi, I would like to contribute this task as my first contribution to gofiber.

From what I read about the logger middleware and the Logger interface, My first thought is that the target can be: "making the logger.Config struct’s LoggerFunc field to accept the Logger interface."

This could include some modifications on the defaultLoggerInstance in the logger middleware. If there is anything I need to be aware of, please feel free to tell me. Thanks!

efectn commented 1 month ago

Hi, I would like to contribute this task as my first contribution to gofiber.

From what I read about the logger middleware and the Logger interface, My first thought is that the target can be: "making the logger.Config struct’s LoggerFunc field to accept the Logger interface."

This could include some modifications on the defaultLoggerInstance in the logger middleware. If there is anything I need to be aware of, please feel free to tell me. Thanks!

Hi @haochunchang feel free to create a PR