hashicorp/nomad · error

failed to prune log files: %v

Error message

failed to prune log files: %v

What it means

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.

Source

Thrown at command/agent/log_file.go:101

func (l *logFile) rotate() error {
	// Get the time from the last point of contact
	timeElapsed := time.Since(l.LastCreated)
	// Rotate if we hit the byte file limit or the time limit
	if (l.BytesWritten >= int64(l.MaxBytes) && (l.MaxBytes > 0)) || timeElapsed >= l.duration {
		l.FileInfo.Close()

		// Move current log file to a timestamped file.
		rotateTime := now()
		rotatefileName := fmt.Sprintf(l.fileNamePattern(), strconv.FormatInt(rotateTime.UnixNano(), 10))
		oldPath := l.FileInfo.Name()
		newPath := filepath.Join(l.logPath, rotatefileName)
		if err := os.Rename(oldPath, newPath); err != nil {
			return fmt.Errorf("failed to rotate log files: %v", err)
		}

		if err := l.pruneFiles(); err != nil {
			return fmt.Errorf("failed to prune log files: %v", err)
		}
		return l.openNew()
	}
	return nil
}

func (l *logFile) pruneFiles() error {
	if l.MaxFiles == 0 {
		return nil
	}
	pattern := l.fileNamePattern()
	//get all the files that match the log file pattern
	globExpression := filepath.Join(l.logPath, fmt.Sprintf(pattern, "*"))
	matches, err := filepath.Glob(globExpression)
	if err != nil {
		return err
	}

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Check permissions on the log directory so old rotated files can be deleted
  2. Clear disk-full or read-only-mount conditions
  3. Inspect the log directory for files owned by another user blocking deletion
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at command/agent/log_file.go:101 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/ad74c59118c5f527. Report an issue: GitHub.