{"record":{"id":"a378da6f2c4db867","repo":"hashicorp/nomad","slug":"no-nomad-log-file-defined","errorCode":null,"errorMessage":"No nomad log file defined","messagePattern":"No nomad log file defined","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"client/agent_endpoint.go","lineNumber":220,"sourceCode":"\tencoder := codec.NewEncoder(conn, structs.MsgpackHandle)\n\n\tif err := decoder.Decode(&args); err != nil {\n\t\thandleStreamResultError(err, new(int64(500)), encoder)\n\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\tnomadLogPath := a.c.GetConfig().LogFile\n\tif args.OnDisk && nomadLogPath == \"\" {\n\t\thandleStreamResultError(errors.New(\"No nomad log file defined\"), new(int64(400)), encoder)\n\t}\n\n\tctx, cancel := context.WithCancel(context.Background())\n\tdefer cancel()\n\topts := monitor.MonitorExportOpts{\n\t\tLogger:       a.c.logger,\n\t\tLogsSince:    args.LogsSince,\n\t\tServiceName:  args.ServiceName,\n\t\tNomadLogPath: nomadLogPath,\n\t\tOnDisk:       args.OnDisk,\n\t\tFollow:       args.Follow,\n\t\tContext:      ctx,\n\t}\n\n\tframes := make(chan *sframer.StreamFrame, streamFramesBuffer)\n\terrCh := make(chan error)\n\tvar buf bytes.Buffer\n\tframeSize := 1024","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/agent_endpoint.go#L202-L238","documentation":"The agent 'monitor' endpoint with on_disk=true tails the Nomad agent's own log file. The file path comes from the agent configuration (log_file). If on_disk is requested but no log file is configured on the agent, there is nothing to tail, so the endpoint returns this 400 error instead of streaming.","triggerScenarios":"Calling the Agent Monitor API with on_disk=true against an agent whose config does not set log_file (the default config may leave it empty or only set log_json/log_level).","commonSituations":"Agents running with default configuration that never set log_file; clients assuming on-disk logging is always enabled; mixed fleets where some agents configure log_file and others do not; upgrades where log_file was removed from config.","solutions":["Set log_file in the agent's config (e.g. log_file = \"/var/log/nomad/\") and restart the agent before using on_disk=true","Use on_disk=false to stream in-memory logs instead of the file","Make the client check/fall back when on-disk logging is unavailable","Standardize log_file across all agent configs"],"exampleFix":"// before (agent config)\n# no log_file set\n// after\nlog_file = \"/var/log/nomad/\"","handlingStrategy":"validation","validationCode":"if req.OnDisk {\n  // confirm the agent has log_file configured (e.g. via agent self)\n  self, err := client.Agent().Self()\n  if err != nil { return err }\n  cfg := self.Config[\"Client\"]\n  if lf, ok := cfg[\"LogFile\"].(string); !ok || lf == \"\" {\n    return errors.New(\"on_disk requested but agent has no log_file configured\")\n  }\n}","typeGuard":null,"tryCatchPattern":"resp, err := client.Agent().Monitor(ctx, ch, &api.MonitorQuery{OnDisk: true})\nif err != nil {\n  if strings.Contains(err.Error(), \"No nomad log file defined\") {\n    // fall back to in-memory log streaming\n    return client.Agent().Monitor(ctx, ch, &api.MonitorQuery{OnDisk: false})\n  }\n  return err\n}","preventionTips":["Always set log_file in agent config when using on_disk log streaming","Probe agent self/config before enabling on_disk","Prefer in-memory streaming unless file persistence is required"],"tags":["api","logging","configuration"],"backgroundTag":"missing-config-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"}