{"record":{"id":"16f458610dc29042","repo":"hashicorp/nomad","slug":"unknown-log-level","errorCode":null,"errorMessage":"Unknown log level","messagePattern":"Unknown log level","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"client/agent_endpoint.go","lineNumber":109,"sourceCode":"\t\treturn\n\t}\n\n\t// Check acl\n\tif aclObj, err := a.c.ResolveToken(args.AuthToken); err != nil {\n\t\thandleStreamResultError(err, new(int64(403)), encoder)\n\t\treturn\n\t} else if !aclObj.AllowAgentRead() {\n\t\thandleStreamResultError(structs.ErrPermissionDenied, new(int64(403)), encoder)\n\t\treturn\n\t}\n\n\tlogLevel := log.LevelFromString(args.LogLevel)\n\tif args.LogLevel == \"\" {\n\t\tlogLevel = log.LevelFromString(\"INFO\")\n\t}\n\n\tif logLevel == log.NoLevel {\n\t\thandleStreamResultError(errors.New(\"Unknown log level\"), new(int64(400)), encoder)\n\t\treturn\n\t}\n\n\tctx, cancel := context.WithCancel(context.Background())\n\tdefer cancel()\n\n\tm := monitor.New(512, a.c.logger, &log.LoggerOptions{\n\t\tJSONFormat:      args.LogJSON,\n\t\tLevel:           logLevel,\n\t\tIncludeLocation: args.LogIncludeLocation,\n\t})\n\n\tframes := make(chan *sframer.StreamFrame, streamFramesBuffer)\n\terrCh := make(chan error)\n\tvar buf bytes.Buffer\n\tframeCodec := codec.NewEncoder(&buf, structs.JsonHandle)\n\n\tframer := sframer.NewStreamFramer(frames, 1*time.Second, 200*time.Millisecond, 1024)","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/agent_endpoint.go#L91-L127","documentation":"Nomad's agent HTTP 'monitor' streaming endpoint validates the requested log level before attaching a log sink. The requested LogLevel string is passed to log.LevelFromString; if it does not parse to a recognized hclog level, the result is log.NoLevel and the endpoint aborts the stream with this 400 error. It exists to fail fast with a clear message instead of silently falling back to a default level.","triggerScenarios":"Calling the Agent Monitor API (GET /v1/agent/monitor) with query/log_level set to a string that is not one of TRACE, DEBUG, INFO, WARN, ERROR (case-insensitive), e.g. 'verbose', 'warning', 'all', or a typo like 'INF0'. An empty string is explicitly allowed (defaults to INFO).","commonSituations":"Hand-built HTTP requests or CLI wrappers passing an invalid --log-level flag; UI clients mapping user-chosen levels to wrong strings; automation scripts using 'warning' instead of 'WARN'.","solutions":["Set log_level to one of TRACE, DEBUG, INFO, WARN, ERROR (case-insensitive) on the monitor request","Omit log_level entirely to default to INFO","Fix the caller/CLI wrapper so it maps friendly level names to hclog-valid levels","Validate the level client-side before issuing the request"],"exampleFix":"// before\nGET /v1/agent/monitor?log_level=warning\n// after\nGET /v1/agent/monitor?log_level=WARN","handlingStrategy":"validation","validationCode":"validLevels := map[string]bool{\"trace\":true,\"debug\":true,\"info\":true,\"warn\":true,\"error\":true}\nif logLevel != \"\" && !validLevels[strings.ToLower(logLevel)] {\n  return fmt.Errorf(\"invalid log_level %q; must be TRACE|DEBUG|INFO|WARN|ERROR\", logLevel)\n}","typeGuard":"func isValidLogLevel(s string) bool {\n  return s == \"\" || log.LevelFromString(s) != log.NoLevel\n}","tryCatchPattern":"// Go: check the HTTP response before streaming\nresp, err := c.Raw(agent.MonitorQuery{LogLevel: lvl})\nif err != nil {\n  if strings.Contains(err.Error(), \"Unknown log level\") {\n    lvl = \"INFO\"\n    return c.Raw(agent.MonitorQuery{LogLevel: lvl})\n  }\n  return err\n}","preventionTips":["Use hclog's level constants/names instead of free-form strings","Validate log level flags in CLI wrappers before calling the API","Omit log_level rather than sending an empty-ish placeholder"],"tags":["api","http","validation","logging"],"backgroundTag":"invalid-argument-value","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}