Documentation
¶
Index ¶
- Constants
- Variables
- func Debug(v ...any)
- func Debugf(format string, v ...any)
- func Debugw(msg string, keysAndValues ...any)
- func Error(v ...any)
- func Errorf(format string, v ...any)
- func Errorw(msg string, keysAndValues ...any)
- func Fatal(v ...any)
- func Fatalf(format string, v ...any)
- func Fatalw(msg string, keysAndValues ...any)
- func Info(v ...any)
- func Infof(format string, v ...any)
- func Infow(msg string, keysAndValues ...any)
- func MustRegisterContextTag(tag string, fn ContextTagFunc)
- func MustSetContextTemplate(config ContextConfig)
- func Panic(v ...any)
- func Panicf(format string, v ...any)
- func Panicw(msg string, keysAndValues ...any)
- func RegisterContextTag(tag string, fn ContextTagFunc) error
- func SetContextTemplate(config ContextConfig) error
- func SetLevel(lv Level)
- func SetLogger[T any](v AllLogger[T])
- func SetOutput(w io.Writer)
- func Trace(v ...any)
- func Tracef(format string, v ...any)
- func Tracew(msg string, keysAndValues ...any)
- func Warn(v ...any)
- func Warnf(format string, v ...any)
- func Warnw(msg string, keysAndValues ...any)
- type AllLogger
- type Buffer
- type CommonLogger
- type ConfigurableLogger
- type ContextConfig
- type ContextData
- type ContextTagFunc
- type FormatLogger
- type Level
- type Logger
- type WithLogger
Constants ¶
const ( TagRequestID = "requestid" TagRequestIDDashed = "request-id" TagUsername = "username" TagAPIKey = "api-key" TagCSRFToken = "csrf-token" TagSessionID = "session-id" )
Tag names registered by Fiber's built-in middlewares. Treat them as the canonical identifiers for the values produced by requestid, basicauth, keyauth, csrf, and session — keeping format strings derived from these constants means renaming a tag here cascades automatically.
const ( // DefaultFormat disables contextual fields for the default logger. DefaultFormat = "" // RequestIDFormat renders the request ID registered by the requestid middleware. RequestIDFormat = "[${" + TagRequestID + "}] " // KeyValueFormat renders commonly registered middleware context values as // key/value fields. Sensitive values (api-key, csrf-token, session-id) are // redacted by the registering middleware before reaching the log line. KeyValueFormat = "request-id=${" + TagRequestIDDashed + "} " + "username=${" + TagUsername + "} " + "api-key=${" + TagAPIKey + "} " + "csrf-token=${" + TagCSRFToken + "} " + "session-id=${" + TagSessionID + "} " )
const TagContextValue = "value:"
TagContextValue reads a value from the bound context-like value using the tag parameter as the key. Use it inside a format string as `${value:KEY}`. The trailing colon is required: it marks the tag as parametric. Registering a tag named "value:" via RegisterContextTag is rejected — the renderer is reserved for context-value lookups.
Variables ¶
var ( // ErrContextTagInvalid is returned by RegisterContextTag and SetContextTemplate // when the supplied tag name or renderer is empty. ErrContextTagInvalid = errors.New("log: context tag name and function are required") // ErrContextTagReserved is returned by RegisterContextTag and SetContextTemplate // when the caller attempts to override the reserved TagContextValue ("value:") tag. ErrContextTagReserved = errors.New("log: context tag is reserved") )
Functions ¶
func Debugw ¶
Debugw logs a message with some additional context. The variadic key-value pairs are treated as they are privateLog With.
func Errorw ¶
Errorw logs a message with some additional context. The variadic key-value pairs are treated as they are privateLog With.
func Fatal ¶
func Fatal(v ...any)
Fatal calls the default logger's Fatal method and then os.Exit(1).
func Fatalw ¶
Fatalw logs a message with some additional context. The variadic key-value pairs are treated as they are privateLog With.
func Infow ¶
Infow logs a message with some additional context. The variadic key-value pairs are treated as they are privateLog With.
func MustRegisterContextTag ¶ added in v3.3.0
func MustRegisterContextTag(tag string, fn ContextTagFunc)
MustRegisterContextTag registers a contextual tag and panics if registration fails.
func MustSetContextTemplate ¶ added in v3.3.0
func MustSetContextTemplate(config ContextConfig)
MustSetContextTemplate configures contextual fields and panics if the format cannot be parsed.
func Panicw ¶
Panicw logs a message with some additional context. The variadic key-value pairs are treated as they are privateLog With.
func RegisterContextTag ¶ added in v3.3.0
func RegisterContextTag(tag string, fn ContextTagFunc) error
RegisterContextTag registers a contextual tag that can be used by SetContextTemplate. Re-registering a tag replaces the existing tag function. Registration is package-global; prefer ContextConfig.CustomTags for per-application overrides. The reserved TagContextValue tag cannot be registered.
func SetContextTemplate ¶ added in v3.3.0
func SetContextTemplate(config ContextConfig) error
SetContextTemplate configures contextual fields rendered by WithContext for Fiber's default logger. Pass an empty ContextConfig (or ContextConfig{Format: DefaultFormat}) to disable contextual fields. It returns an error if config.Format cannot be parsed or if config.CustomTags attempts to override the reserved TagContextValue tag.
func SetLevel ¶
func SetLevel(lv Level)
SetLevel sets the level of logs below which logs will not be output. The default logger is LevelTrace. Note that this method is not concurrent-safe.
func SetLogger ¶
SetLogger sets the default logger and the system logger. Note that this method is not concurrent-safe and must not be called after the use of DefaultLogger and global functions from this package.
func SetOutput ¶
SetOutput sets the output of default logger and system logger. By default, it is stderr.
Types ¶
type AllLogger ¶
type AllLogger[T any] interface { CommonLogger ConfigurableLogger[T] // WithContext returns a new logger with the given context. WithContext(ctx any) CommonLogger }
AllLogger is the combination of CommonLogger, context binding, and ConfigurableLogger. Custom extensions can be made through AllLogger
func DefaultLogger ¶
DefaultLogger returns the default logger.
type Buffer ¶ added in v3.3.0
type Buffer = logtemplate.Buffer
Buffer abstracts the buffer operations used when rendering contextual log fields.
type CommonLogger ¶
type CommonLogger interface {
Logger
FormatLogger
WithLogger
}
CommonLogger is the set of logging operations available across Fiber's logging implementations.
func WithContext ¶
func WithContext(ctx any) CommonLogger
WithContext binds the default logger to the provided context and returns the contextualized logger.
type ConfigurableLogger ¶
type ConfigurableLogger[T any] interface { // SetLevel sets logging level. // // Available levels: Trace, Debug, Info, Warn, Error, Fatal, Panic. SetLevel(level Level) // SetOutput sets the logger output. SetOutput(w io.Writer) // Logger returns the logger instance. It can be used to adjust the logger configurations in case of need. Logger() T }
ConfigurableLogger provides methods to config a logger.
type ContextConfig ¶ added in v3.3.0
type ContextConfig struct {
// CustomTags defines additional contextual tags available to Format.
// The built-in TagContextValue ("value:") tag cannot be overridden.
CustomTags map[string]ContextTagFunc
// Format defines the contextual prefix rendered before the log message.
// Use CustomTags to expose package-specific values such as request IDs.
Format string
}
ContextConfig defines how WithContext enriches logs emitted by Fiber's default logger.
type ContextData ¶ added in v3.3.0
type ContextData struct{}
ContextData is reserved for data shared by contextual log tags. It currently has no fields; the type exists so the ContextTagFunc signature can evolve without breaking custom-tag implementations.
type ContextTagFunc ¶ added in v3.3.0
type ContextTagFunc = logtemplate.Func[any, ContextData]
ContextTagFunc renders one contextual log tag.
type FormatLogger ¶
type FormatLogger interface {
Tracef(format string, v ...any)
Debugf(format string, v ...any)
Infof(format string, v ...any)
Warnf(format string, v ...any)
Errorf(format string, v ...any)
Fatalf(format string, v ...any)
Panicf(format string, v ...any)
}
FormatLogger is a logger interface that output logs with a format.
type Level ¶
type Level int
Level defines the priority of a log message. When a logger is configured with a level, any log message with a lower log level (smaller by integer comparison) will not be output.
type Logger ¶
type Logger interface {
Trace(v ...any)
Debug(v ...any)
Info(v ...any)
Warn(v ...any)
Error(v ...any)
Fatal(v ...any)
Panic(v ...any)
}
Logger is a logger interface that provides logging function with levels.
type WithLogger ¶
type WithLogger interface {
Tracew(msg string, keysAndValues ...any)
Debugw(msg string, keysAndValues ...any)
Infow(msg string, keysAndValues ...any)
Warnw(msg string, keysAndValues ...any)
Errorw(msg string, keysAndValues ...any)
Fatalw(msg string, keysAndValues ...any)
Panicw(msg string, keysAndValues ...any)
}
WithLogger is a logger interface that output logs with a message and key-value pairs.