{"id":"c560762fbe6ba70a","repo":"gofiber/fiber","slug":"logger-tag-name-and-function-are-required","errorCode":null,"errorMessage":"logger: tag name and function are required","messagePattern":"logger: tag name and function are required","errorType":"validation","errorClass":"ErrTagInvalid","httpStatus":null,"severity":"error","filePath":"middleware/logger/tags.go","lineNumber":57,"sourceCode":"\tTagRespHeader        = \"respHeader:\"\n\tTagLocals            = \"locals:\"\n\tTagQuery             = \"query:\"\n\tTagForm              = \"form:\"\n\tTagCookie            = \"cookie:\"\n\tTagBlack             = \"black\"\n\tTagRed               = \"red\"\n\tTagGreen             = \"green\"\n\tTagYellow            = \"yellow\"\n\tTagBlue              = \"blue\"\n\tTagMagenta           = \"magenta\"\n\tTagCyan              = \"cyan\"\n\tTagWhite             = \"white\"\n\tTagReset             = \"reset\"\n)\n\n// ErrTagInvalid is returned by RegisterTag and panicked from MustRegisterTag\n// when the supplied tag name or renderer is empty.\nvar ErrTagInvalid = errors.New(\"logger: tag name and function are required\")\n\nvar registeredTags = struct {\n\tm map[string]LogFunc\n\tsync.RWMutex\n}{\n\tm: make(map[string]LogFunc),\n}\n\n// RegisterTag registers a global logger middleware tag.\n// Registered tags are available to logger middleware instances created after\n// registration and can be overridden per instance with Config.CustomTags.\n// Re-registering a tag replaces the existing tag function.\nfunc RegisterTag(tag string, fn LogFunc) error {\n\tif tag == \"\" || fn == nil {\n\t\treturn ErrTagInvalid\n\t}\n\n\tregisteredTags.Lock()","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/gofiber/fiber/blob/9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c/middleware/logger/tags.go#L39-L75","documentation":"Returned by logger.RegisterTag (tags.go:57, 72) when either the tag name is an empty string or the renderer function (LogFunc) is nil. Both are required for a tag to be usable in format templates. MustRegisterTag panics with the same error. Since registered tags are global and shared across logger instances, an invalid registration would break template compilation for every logger that references the tag.","triggerScenarios":"Calling logger.RegisterTag(\"\", fn) or logger.RegisterTag(\"mytag\", nil); passing an empty name or nil function from dynamic code (e.g. reading tag definitions from config); a conditional that leaves fn nil.","commonSituations":"Programmatic tag registration where the name comes from external config that might be empty; refactoring that accidentally passes nil for the function; conditional registration logic that doesn't guard against empty inputs.","solutions":["Validate that both the tag name and function are non-empty/non-nil before calling RegisterTag.","If registering from config, skip or log a warning when either value is missing instead of calling RegisterTag."],"exampleFix":"// before\nlogger.RegisterTag(tagName, tagFn) // tagName or tagFn may be empty\n// after\nif tagName != \"\" && tagFn != nil {\n  logger.RegisterTag(tagName, tagFn)\n}","handlingStrategy":"validation","validationCode":"// Guard registration against empty inputs\nif tagName != \"\" && tagFn != nil {\n    if err := logger.RegisterTag(tagName, tagFn); err != nil {\n        log.Printf(\"failed to register tag %q: %v\", tagName, err)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always check both name and function are non-empty/non-nil before RegisterTag.","When loading tags from config, validate and skip incomplete entries.","Unit test tag registration paths with empty/nil inputs."],"tags":["logger","configuration","validation","tags"],"analyzedSha":"9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c","analyzedAt":"2026-08-04T21:44:03.395Z","schemaVersion":2}