gofiber/fiber · error
logger: tag name and function are required
Error message
logger: tag name and function are required
What it means
Returned by middleware/logger.RegisterTag (and panicked from MustRegisterTag) when the tag name is empty or the renderer function is nil. Registration replaces existing tags, so both inputs must be valid before the map is mutated. The guard runs first, before acquiring the lock.
Solutions
- Provide a non-empty tag name and a non-nil LogFunc to RegisterTag.
- If registering from a map, skip or reject entries with empty keys or nil functions before calling RegisterTag.
- Use RegisterTag (not MustRegisterTag) when inputs come from untrusted/config sources so a bad entry is an error, not a panic.
Example fix
// before
logger.MustRegisterTag(name, nilFn) // panics
// after
if name != "" && fn != nil {
logger.RegisterTag(name, fn)
} Defensive patterns
Strategy: validation
Validate before calling
if name == "" || fn == nil {
return logger.ErrTagInvalid
} Try / catch
if err := logger.RegisterTag(name, fn); err != nil {
if errors.Is(err, logger.ErrTagInvalid) {
// skip this entry; name or fn was empty
}
} Prevention
- Filter empty keys and nil functions before bulk-registering from a map.
- Prefer RegisterTag over MustRegisterTag when inputs come from config.
- Unit-test registration paths with both invalid inputs.
When it happens
Trigger: Calling RegisterTag("", fn), RegisterTag(name, nil), or MustRegisterTag with either invalid argument. Common when tag names are generated dynamically and an entry is missing.
Common situations: Building tag registrations from a config map where one entry has an empty key or a nil function; refactoring that left a nil LogFunc; a loop that registers tags but skips setting fn for some.
Related errors
- ErrUnknownTag
- logger: unknown template tag
- ErrTagInvalid
- log: context tag is reserved
- logger: RegisterContextTag requires a non-empty name and…
AI-assisted analysis of gofiber/fiber@a105acad6c (2026-08-11).
Data as JSON: /api/errors/c560762fbe6ba70a.
Report an issue: GitHub.
Appendix: source
Thrown at middleware/logger/tags.go:57
TagRespHeader = "respHeader:"
TagLocals = "locals:"
TagQuery = "query:"
TagForm = "form:"
TagCookie = "cookie:"
TagBlack = "black"
TagRed = "red"
TagGreen = "green"
TagYellow = "yellow"
TagBlue = "blue"
TagMagenta = "magenta"
TagCyan = "cyan"
TagWhite = "white"
TagReset = "reset"
)
// ErrTagInvalid is returned by RegisterTag and panicked from MustRegisterTag
// when the supplied tag name or renderer is empty.
var ErrTagInvalid = errors.New("logger: tag name and function are required")
var registeredTags = struct {
m map[string]LogFunc
sync.RWMutex
}{
m: make(map[string]LogFunc),
}
// RegisterTag registers a global logger middleware tag.
// Registered tags are available to logger middleware instances created after
// registration and can be overridden per instance with Config.CustomTags.
// Re-registering a tag replaces the existing tag function.
func RegisterTag(tag string, fn LogFunc) error {
if tag == "" || fn == nil {
return ErrTagInvalid
}
registeredTags.Lock()View on GitHub (pinned to a105acad6c)