{"record":{"id":"ad74c59118c5f527","repo":"hashicorp/nomad","slug":"failed-to-prune-log-files-v","errorCode":null,"errorMessage":"failed to prune log files: %v","messagePattern":"failed to prune log files: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/agent/log_file.go","lineNumber":101,"sourceCode":"\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)\n\tif err != nil {\n\t\treturn err\n\t}\n","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/agent/log_file.go#L83-L119","documentation":"Fires in logFile.rotate after the log has been rolled over to a timestamped file: pruning the old, rotated log files from the log directory failed (permissions or filesystem error), so stale logs may accumulate.","triggerScenarios":"Thrown at command/agent/log_file.go:101 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check permissions on the log directory so old rotated files can be deleted","Clear disk-full or read-only-mount conditions","Inspect the log directory for files owned by another user blocking deletion"],"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"}