{"record":{"id":"57de794295dc5ca0","repo":"vitessio/vitess","slug":"the-logging-module-doesn-t-specify-a-log-dir-flag","errorCode":null,"errorMessage":"the logging module doesn't specify a log_dir flag","messagePattern":"the logging module doesn't specify a log_dir flag","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/logutil/purge.go","lineNumber":122,"sourceCode":"\t\tif mtimeDelta != 0 {\n\t\t\tmodifiedTs, err := getModifiedTimestamp(file)\n\t\t\tif err != nil {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tpurgeFile = purgeFile || now.Sub(modifiedTs) > mtimeDelta\n\t\t}\n\t\tif purgeFile {\n\t\t\tos.Remove(file)\n\t\t}\n\t}\n}\n\n// PurgeLogs removes any log files that were started more than\n// keepLogs ago and that aren't the current log.\nfunc PurgeLogs() {\n\tf := _flag.Lookup(\"log_dir\")\n\tif f == nil {\n\t\tpanic(\"the logging module doesn't specify a log_dir flag\")\n\t}\n\tif keepLogsByCtime == 0 && keepLogsByMtime == 0 {\n\t\treturn\n\t}\n\tlogDir := f.Value.String()\n\tprogram := filepath.Base(os.Args[0])\n\tticker := time.NewTicker(purgeLogsInterval)\n\n\tgo func() {\n\t\tfor range ticker.C {\n\t\t\tpurgeLogsOnce(time.Now(), logDir, program, keepLogsByCtime, keepLogsByMtime)\n\t\t}\n\t}()\n}\n","sourceCodeStart":104,"sourceCodeEnd":137,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/logutil/purge.go#L104-L137","documentation":"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.","triggerScenarios":"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.","commonSituations":"Custom main() setups that call PurgeLogs without running the standard logutil flag registration / ParseFlags flow; tests constructing a bare FlagSet without log_dir.","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"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if _flag.Lookup(\"log_dir\") == nil { return } // check before relying on PurgeLogs; or ensure logutil.ParseFlags ran first","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always initialize logging via logutil.ParseFlags / CobraPreRunE before purge","Don't call PurgeLogs in nonstandard bootstrap paths","Keep the standard vitess command wiring intact"],"tags":["go","panic","logging","flags"],"backgroundTag":"missing-flag-registration","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}