{"record":{"id":"8745fb53bc5e62ff","repo":"hashicorp/nomad","slug":"failed-to-rotate-log-files-v","errorCode":null,"errorMessage":"failed to rotate log files: %v","messagePattern":"failed to rotate log files: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/agent/log_file.go","lineNumber":97,"sourceCode":"\tl.BytesWritten = stat.Size()\n\tl.LastCreated = l.createTime(stat)\n\treturn nil\n}\n\nfunc (l *logFile) rotate() error {\n\t// Get the time from the last point of contact\n\ttimeElapsed := time.Since(l.LastCreated)\n\t// Rotate if we hit the byte file limit or the time limit\n\tif (l.BytesWritten >= int64(l.MaxBytes) && (l.MaxBytes > 0)) || timeElapsed >= l.duration {\n\t\tl.FileInfo.Close()\n\n\t\t// Move current log file to a timestamped file.\n\t\trotateTime := now()\n\t\trotatefileName := fmt.Sprintf(l.fileNamePattern(), strconv.FormatInt(rotateTime.UnixNano(), 10))\n\t\toldPath := l.FileInfo.Name()\n\t\tnewPath := filepath.Join(l.logPath, rotatefileName)\n\t\tif err := os.Rename(oldPath, newPath); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to rotate log files: %v\", err)\n\t\t}\n\n\t\tif err := l.pruneFiles(); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to prune log files: %v\", err)\n\t\t}\n\t\treturn l.openNew()\n\t}\n\treturn nil\n}\n\nfunc (l *logFile) pruneFiles() error {\n\tif l.MaxFiles == 0 {\n\t\treturn nil\n\t}\n\tpattern := l.fileNamePattern()\n\t//get all the files that match the log file pattern\n\tglobExpression := filepath.Join(l.logPath, fmt.Sprintf(pattern, \"*\"))\n\tmatches, err := filepath.Glob(globExpression)","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/agent/log_file.go#L79-L115","documentation":"Thrown by logFile.rotate when renaming the active log file to its timestamped replacement (or subsequent rotation bookkeeping) fails; the wrapped os error is surfaced so log writes report rotation failure to callers.","triggerScenarios":"Thrown at command/agent/log_file.go:97 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check filesystem permissions on the log directory and the old log file","Verify the disk is not full and the path is writable by the Nomad agent user","Check for stale file locks or the file being open by another process (e.g. log collector)"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}