Skip to main content
Version: Next


Logger middleware for Fiber that logs HTTP request/response details.


func New(config ...Config) fiber.Handler


Import the middleware package that is part of the Fiber web framework

import (

The order of registration plays a role. Only all routes that are registered after this one will be logged. The middleware should therefore be one of the first to be registered.

After you initiate your Fiber app, you can use the following possibilities:

// Initialize default config

// Or extend your config for customization
// Logging remote IP and Port
Format: "[${ip}]:${port} ${status} - ${method} ${path}\n",

// Logging Request ID
// For more options, see the Config section
Format: "${pid} ${locals:requestid} ${status} - ${method} ${path}​\n",

// Changing TimeZone & TimeFormat
Format: "${pid} ${status} - ${method} ${path}\n",
TimeFormat: "02-Jan-2006",
TimeZone: "America/New_York",

// Custom File Writer
file, err := os.OpenFile("./123.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatalf("error opening file: %v", err)
defer file.Close()
Output: file,

// Add Custom Tags
CustomTags: map[string]logger.LogFunc{
"custom_tag": func(output logger.Buffer, c fiber.Ctx, data *logger.Data, extraParam string) (int, error) {
return output.WriteString("it is a custom tag")

// Callback after log is written
TimeFormat: time.RFC3339Nano,
TimeZone: "Asia/Shanghai",
Done: func(c fiber.Ctx, logString []byte) {
if c.Response().StatusCode() != fiber.StatusOK {

// Disable colors when outputting to default format
DisableColors: true,

Writing to os.File is goroutine-safe, but if you are using a custom Output that is not goroutine-safe, make sure to implement locking to properly serialize writes.



Nextfunc(fiber.Ctx) boolNext defines a function to skip this middleware when returned true.nil
Donefunc(fiber.Ctx, []byte)Done is a function that is called after the log string for a request is written to Output, and pass the log string as parameter.nil
CustomTagsmap[string]LogFunctagFunctions defines the custom tag[string]LogFunc
FormatstringFormat defines the logging tags.[${time}] ${ip} ${status} - ${latency} ${method} ${path} ${error}\n
TimeFormatstringTimeFormat defines the time format for log timestamps.15:04:05
TimeZonestringTimeZone can be specified, such as "UTC" and "America/New_York" and "Asia/Chongqing", etc"Local"
TimeIntervaltime.DurationTimeInterval is the delay before the timestamp is updated.500 * time.Millisecond
Outputio.WriterOutput is a writer where logs are written.os.Stdout
DisableColorsboolDisableColors defines if the logs output should be colorized.false
enableColorsboolInternal field for enabling colors in the log output. (This is not a user-configurable field)-
enableLatencyboolInternal field for enabling latency measurement in logs. (This is not a user-configurable field)-
timeZoneLocation*time.LocationInternal field for the time zone location. (This is not a user-configurable field)-

Default Config

var ConfigDefault = Config{
Next: nil,
Done: nil,
Format: "[${time}] ${ip} ${status} - ${latency} ${method} ${path} ${error}\n",
TimeFormat: "15:04:05",
TimeZone: "Local",
TimeInterval: 500 * time.Millisecond,
Output: os.Stdout,
DisableColors: false,


// Logger variables
const (
TagPid = "pid"
TagTime = "time"
TagReferer = "referer"
TagProtocol = "protocol"
TagPort = "port"
TagIP = "ip"
TagIPs = "ips"
TagHost = "host"
TagMethod = "method"
TagPath = "path"
TagURL = "url"
TagUA = "ua"
TagLatency = "latency"
TagStatus = "status" // response status
TagResBody = "resBody" // response body
TagReqHeaders = "reqHeaders"
TagQueryStringParams = "queryParams" // request query parameters
TagBody = "body" // request body
TagBytesSent = "bytesSent"
TagBytesReceived = "bytesReceived"
TagRoute = "route"
TagError = "error"
// DEPRECATED: Use TagReqHeader instead
TagHeader = "header:" // request header
TagReqHeader = "reqHeader:" // request header
TagRespHeader = "respHeader:" // response header
TagQuery = "query:" // request query
TagForm = "form:" // request form
TagCookie = "cookie:" // request cookie
TagLocals = "locals:"
// colors
TagBlack = "black"
TagRed = "red"
TagGreen = "green"
TagYellow = "yellow"
TagBlue = "blue"
TagMagenta = "magenta"
TagCyan = "cyan"
TagWhite = "white"
TagReset = "reset"