{"record":{"id":"daad630f937ba7c8","repo":"hashicorp/nomad","slug":"failed-to-create-stdout-logfile-for-q-v","errorCode":null,"errorMessage":"failed to create stdout logfile for %q: %v","messagePattern":"failed to create stdout logfile for %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/logmon/logmon.go","lineNumber":144,"sourceCode":"\t\t\ttl.lro.Close()\n\t\t})\n\t}\n\tif tl.lre != nil {\n\t\twg.Go(func() {\n\t\t\ttl.lre.Close()\n\t\t})\n\t}\n\twg.Wait()\n}\n\nfunc NewTaskLogger(cfg *LogConfig, logger hclog.Logger) (*TaskLogger, error) {\n\ttl := &TaskLogger{config: cfg}\n\n\tlogFileSize := int64(cfg.MaxFileSizeMB * 1024 * 1024)\n\tlro, err := logging.NewFileRotator(cfg.LogDir, cfg.StdoutLogFile,\n\t\tcfg.MaxFiles, logFileSize, logger)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create stdout logfile for %q: %v\", cfg.StdoutLogFile, err)\n\t}\n\n\twrapperOut, err := newLogRotatorWrapper(cfg.StdoutFifo, logger, lro)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\ttl.lro = wrapperOut\n\n\tlre, err := logging.NewFileRotator(cfg.LogDir, cfg.StderrLogFile,\n\t\tcfg.MaxFiles, logFileSize, logger)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create stderr logfile for %q: %v\", cfg.StderrLogFile, err)\n\t}\n\n\twrapperErr, err := newLogRotatorWrapper(cfg.StderrFifo, logger, lre)\n\tif err != nil {\n\t\treturn nil, err","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/logmon/logmon.go#L126-L162","documentation":"logmon.NewTaskLogger creates the stdout file rotator for a task before wiring the FIFO wrapper; if logging.NewFileRotator fails (cannot create/open the stdout log file), the task logger creation aborts with this wrapped error naming the stdout log file. It means log files could not be set up in the task's log directory.","triggerScenarios":"NewFileRotator failing for the stdout file: LogDir does not exist or is not writable, disk full, path too long, or permission denied on the log directory; invalid MaxFiles/MaxFileSizeMB configuration.","commonSituations":"Log directory volume not mounted or owned by another user in containers; read-only filesystem; disk quota exceeded; misconfigured client \"log_dir\" option; SELinux blocking writes to the log path.","solutions":["Verify cfg.LogDir exists, is writable by the client process, and has free space","Check the wrapped error: EACCES -> fix ownership/permissions, ENOSPC -> free disk, ENOENT -> create/mount the dir","Correct client config (log_dir, max_files, max_file_size) in the agent configuration","Check SELinux/AppArmor policies permitting writes to the log directory","Run logmon with the same effective user that owns the task log dir"],"exampleFix":"// before\nlro, err := logging.NewFileRotator(\"/nonexistent/dir\", name, ...) // ENOENT\n// after\nif err := os.MkdirAll(cfg.LogDir, 0o755); err != nil {\n    return nil, fmt.Errorf(\"cannot create log dir: %w\", err)\n}\nlro, err := logging.NewFileRotator(cfg.LogDir, name, ...)","handlingStrategy":"validation","validationCode":"func ensureLogDirUsable(dir string) error {\n    if err := os.MkdirAll(dir, 0o755); err != nil {\n        return fmt.Errorf(\"log dir not creatable: %w\", err)\n    }\n    probe := filepath.Join(dir, \".probe\")\n    if err := os.WriteFile(probe, []byte(\"x\"), 0o600); err != nil {\n        return fmt.Errorf(\"log dir not writable: %w\", err)\n    }\n    return os.Remove(probe)\n}","typeGuard":null,"tryCatchPattern":"tl, err := NewTaskLogger(cfg)\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to create stdout logfile\") {\n        return fmt.Errorf(\"check log_dir permissions and disk space: %w\", err)\n    }\n    return err\n}","preventionTips":["Validate log_dir exists and is writable before starting tasks","Monitor disk space/quota on the log volume","Set sane max_files and max_file_size values","Ensure the client user owns or can write the log directory"],"tags":["logging","logmon","filesystem","configuration"],"backgroundTag":"log-file-creation-failed","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"}