Documentation ¶
Index ¶
Constants ¶
View Source
const ( FieldReferer = "referer" FieldProtocol = "protocol" FieldPID = "pid" FieldPort = "port" FieldIP = "ip" FieldIPs = "ips" FieldHost = "host" FieldPath = "path" FieldURL = "url" FieldUserAgent = "ua" FieldLatency = "latency" FieldStatus = "status" FieldResBody = "resBody" FieldQueryParams = "queryParams" FieldBody = "body" FieldBytesReceived = "bytesReceived" FieldBytesSent = "bytesSent" FieldRoute = "route" FieldMethod = "method" FieldRequestID = "requestId" FieldError = "error" FieldReqHeaders = "reqHeaders" FieldResHeaders = "resHeaders" )
Variables ¶
View Source
var ConfigDefault = Config{ Next: nil, Logger: &logger, Fields: []string{FieldIP, FieldLatency, FieldStatus, FieldMethod, FieldURL, FieldError}, Messages: []string{"Server error", "Client error", "Success"}, Levels: []zerolog.Level{zerolog.ErrorLevel, zerolog.WarnLevel, zerolog.InfoLevel}, }
ConfigDefault is the default config
Functions ¶
Types ¶
type Config ¶
type Config struct { // Next defines a function to skip this middleware when returned true. // // Optional. Default: nil Next func(c *fiber.Ctx) bool // SkipBody defines a function to skip log "body" field when returned true. // // Optional. Default: nil SkipBody func(c *fiber.Ctx) bool // SkipResBody defines a function to skip log "resBody" field when returned true. // // Optional. Default: nil SkipResBody func(c *fiber.Ctx) bool // GetResBody defines a function to get ResBody. // eg: when use compress middleware, resBody is unreadable. you can set GetResBody func to get readable resBody. // // Optional. Default: nil GetResBody func(c *fiber.Ctx) []byte // Skip logging for these uri // // Optional. Default: nil SkipURIs []string // Add custom zerolog logger. // // Optional. Default: zerolog.New(os.Stderr).With().Timestamp().Logger() Logger *zerolog.Logger // GetLogger defines a function to get custom zerolog logger. // eg: when we need to create a new logger for each request. // // GetLogger will override Logger. // // Optional. Default: nil GetLogger func(c *fiber.Ctx) zerolog.Logger // Add fields what you want see. // // Optional. Default: {"ip", "latency", "status", "method", "url", "error"} Fields []string // Wrap headers to dictionary. // If false: {"method":"POST", "header-key":"header value"} // If true: {"method":"POST", "reqHeaders": {"header-key":"header value"}} // // Optional. Default: false WrapHeaders bool // Use snake case for fields: FieldResBody, FieldQueryParams, FieldBytesReceived, FieldBytesSent, FieldRequestId, FieldReqHeaders, FieldResHeaders. // If false: {"method":"POST", "resBody":"v", "queryParams":"v"} // If true: {"method":"POST", "res_body":"v", "query_params":"v"} // // Optional. Default: false FieldsSnakeCase bool // Custom response messages. // Response codes >= 500 will be logged with Messages[0]. // Response codes >= 400 will be logged with Messages[1]. // Other response codes will be logged with Messages[2]. // You can specify less, than 3 messages, but you must specify at least 1. // Specifying more than 3 messages is useless. // // Optional. Default: {"Server error", "Client error", "Success"} Messages []string // Custom response levels. // Response codes >= 500 will be logged with Levels[0]. // Response codes >= 400 will be logged with Levels[1]. // Other response codes will be logged with Levels[2]. // You can specify less, than 3 levels, but you must specify at least 1. // Specifying more than 3 levels is useless. // // Optional. Default: {zerolog.ErrorLevel, zerolog.WarnLevel, zerolog.InfoLevel} Levels []zerolog.Level }
Config defines the config for middleware.
Click to show internal directories.
Click to hide internal directories.