Logger

Logger middleware logs the information about each HTTP request.

Installation

  1. go get -u github.com/gofiber/logger

Signature

  1. logger.new(config ...Config) func(*Ctx)

Config

PropertyTypeDescriptionDefault
Filterfunc(*fiber.Ctx) boolDefines a function to skip middlewarenil
FormatstringPossible values: time, ip, url, host, method, path, protocol, referer, ua, header:<key>, query:<key>, form:<key>, cookie:<key>“${time} - ${ip} - ${method} ${path}\t${ua}\n”
TimeFormatstringTimeFormat read more here15:04:05
Outputio.WriterOutput is a writter where logs are writtenos.Stderr

Example

  1. package main
  2.  
  3. import (
  4. "github.com/gofiber/fiber"
  5. "github.com/gofiber/logger"
  6. )
  7.  
  8. func main() {
  9. app := fiber.New()
  10.  
  11. app.Use(logger.New())
  12.  
  13. app.Get("/", func(c *fiber.Ctx) {
  14. c.Send("Welcome!")
  15. })
  16.  
  17. app.Listen(3000)
  18. }