vitessio/vitess · error
the logging module doesn't specify a log_dir flag
Error message
the logging module doesn't specify a log_dir flag
What it means
logutil.PurgeLogs looks up the log_dir flag in the logging package's private flag set. If the flag is absent, the logging module was not initialized as expected, so log directory purging cannot proceed and it panics. This guards an internal invariant of the logging package.
Source
Thrown at go/vt/logutil/purge.go:122
if mtimeDelta != 0 {
modifiedTs, err := getModifiedTimestamp(file)
if err != nil {
continue
}
purgeFile = purgeFile || now.Sub(modifiedTs) > mtimeDelta
}
if purgeFile {
os.Remove(file)
}
}
}
// PurgeLogs removes any log files that were started more than
// keepLogs ago and that aren't the current log.
func PurgeLogs() {
f := _flag.Lookup("log_dir")
if f == nil {
panic("the logging module doesn't specify a log_dir flag")
}
if keepLogsByCtime == 0 && keepLogsByMtime == 0 {
return
}
logDir := f.Value.String()
program := filepath.Base(os.Args[0])
ticker := time.NewTicker(purgeLogsInterval)
go func() {
for range ticker.C {
purgeLogsOnce(time.Now(), logDir, program, keepLogsByCtime, keepLogsByMtime)
}
}()
}
View on GitHub (pinned to 01a25a7d17)
Solutions
- Ensure logutil flag registration (which defines log_dir) runs before PurgeLogs — typically via logutil.ParseFlags or CobraPreRunE in your command setup
- Do not call PurgeLogs in code paths that bypass the standard flag registration
- Verify you are using the logutil package's own flag set, not a separate one
Defensive patterns
Strategy: validation
Validate before calling
if _flag.Lookup("log_dir") == nil { return } // check before relying on PurgeLogs; or ensure logutil.ParseFlags ran first Prevention
- Always initialize logging via logutil.ParseFlags / CobraPreRunE before purge
- Don't call PurgeLogs in nonstandard bootstrap paths
- Keep the standard vitess command wiring intact
When it happens
Trigger: Calling logutil.PurgeLogs before the logging flags (including log_dir) have been registered via the package's flag registration, or using a flag set that did not include the logging module's flags.
Common situations: Custom main() setups that call PurgeLogs without running the standard logutil flag registration / ParseFlags flow; tests constructing a bare FlagSet without log_dir.
Related errors
- unsupported profile mode
- --batch-size requires 'direct' ddl_strategy
- --batch-size conflicts with --uuid-list. Batching does not s
- missing value for 'rate'
- missing value for 'path'
AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01).
Data as JSON: /api/errors/57de794295dc5ca0.
Report an issue: GitHub.