Fiber: ๐Ÿ”ฅ Fast logger middleware

Created on 3 Feb 2020  ยท  4Comments  ยท  Source: gofiber/fiber

Is your feature request related to a problem? Please describe.

I'm not sure if there were any plans to write your own logger (as middleware?), but it would be very cool to add a logger from Uber โ€” zap. It's blazing fast, structured, leveled logging system.

Describe the solution you'd like

For one of my side project (Create Go App, to be exact), I created web app template for Fiber with example usage of zap logger:

Describe alternatives you've considered

As alternative solution, I know only Logrus, but he's very slow and doesn't have flexible structure for configuring (_really, when I read zap's docs and source code, I found every things, which I wanted to re-configure_).

Therefore, I don't recommend to use Logrus for Fiber, but good to know! ๐Ÿ˜‰

Additional context

I'm ready to discus about this various feature for every web frameworks and may (want) help to write logger middleware, if needed. Please, let me know what you think!

Most helpful comment

I have created a simple logger https://github.com/gofiber/fiber/blob/master/middleware/morgan.go, this is just an example on how internal middlewares are build up.

package main

import (
  "github.com/gofiber/fiber"
  "github.com/gofiber/fiber/middleware"
)

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

  app.Use(middleware.Morgan())
  // app.Use(middleware.Cors())
  // app.Use(middleware.Helmet())
  // app.Use(middleware.Session())
  // app.Use(middleware.CSurf())
  // app.Use(middleware.Limiter())
  // etc...

  app.Get("/", func(c *fiber.Ctx) {
    c.Send("Hello, World!")
  })

  app.Listen(3000)
}

I would like to replicate the following express middlewares for fiber this month:

All 4 comments

@koddr, great suggestion. I'm not home right now but I want to finish the middleware structure tomorrow so we can start writing many midware apps.

Regarding the logger idea, it looks like a good tool. I would like a morgan like system for fiber.

I will continue tonight to get the middleware package ready for development.

Middleware plans for feb

  • Helmet _(security headers)_
  • Morgan _(logger)_
  • Cors _(cors headers)_

I have created a simple logger https://github.com/gofiber/fiber/blob/master/middleware/morgan.go, this is just an example on how internal middlewares are build up.

package main

import (
  "github.com/gofiber/fiber"
  "github.com/gofiber/fiber/middleware"
)

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

  app.Use(middleware.Morgan())
  // app.Use(middleware.Cors())
  // app.Use(middleware.Helmet())
  // app.Use(middleware.Session())
  // app.Use(middleware.CSurf())
  // app.Use(middleware.Limiter())
  // etc...

  app.Get("/", func(c *fiber.Ctx) {
    c.Send("Hello, World!")
  })

  app.Listen(3000)
}

I would like to replicate the following express middlewares for fiber this month:

@Fenny wow, it's good point ๐Ÿ‘

One little question about naming of logger: _can we change/symlinked it?_ I mean, Morgan for logger it's okay, but not really (for some people, who doesn't know Node.js ecosystem).

Would be great and more understandable โ€” re-name Morgan to Logger and hide info (like _easter egg_) about it to comments into middleware file ./middleware/logger.go OR create _symlink_ to this function (to have access to both Morgan() and Logger()), If you want to keep this naming.

I know, you have good Node.js background, but sometimes, similar naming (without fallback to understandable) is huge trouble to promote project to all layers of coders around the programming languages (and stacks).

Please, think about it ๐Ÿ˜‰

Agreed :+1:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

peterbourgon picture peterbourgon  ยท  4Comments

jeyraj picture jeyraj  ยท  4Comments

abowloflrf picture abowloflrf  ยท  4Comments

bashery picture bashery  ยท  4Comments

GrigoriyMikhalkin picture GrigoriyMikhalkin  ยท  4Comments