Logger
Logger middleware logs the information about each HTTP request.
Installation
- go get -u github.com/gofiber/logger
Signature
- logger.new(config ...Config) func(*Ctx)
Config
Property | Type | Description | Default |
---|---|---|---|
Filter | func(*fiber.Ctx) bool | Defines a function to skip middleware | nil |
Format | string | Possible 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” |
TimeFormat | string | TimeFormat read more here | 15:04:05 |
Output | io.Writer | Output is a writter where logs are written | os.Stderr |
Example
- package main
- import (
- "github.com/gofiber/fiber"
- "github.com/gofiber/logger"
- )
- func main() {
- app := fiber.New()
- app.Use(logger.New())
- app.Get("/", func(c *fiber.Ctx) {
- c.Send("Welcome!")
- })
- app.Listen(3000)
- }