Merge pull request #11387 from vigothehacker/issue-11382

Use the first non flag argument for the log file name instead of the first argument
pull/11491/head
Steven Powell 2021-05-20 15:51:33 -07:00 committed by GitHub
commit a60a6e215b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View File

@ -152,7 +152,7 @@ func logFileName(dir string, logIdx int64) string {
klog.Warningf("Unable to add username %s to log filename hash: %v", user.Username, err)
}
}
for _, s := range os.Args {
for _, s := range pflag.Args() {
if _, err := h.Write([]byte(s)); err != nil {
klog.Warningf("Unable to add arg %s to log filename hash: %v", s, err)
}
@ -160,10 +160,10 @@ func logFileName(dir string, logIdx int64) string {
hs := hex.EncodeToString(h.Sum(nil))
var logfilePath string
// check if subcommand specified
if len(os.Args) < 2 {
if len(pflag.Args()) < 1 {
logfilePath = filepath.Join(dir, fmt.Sprintf("minikube_%s_%d.log", hs, logIdx))
} else {
logfilePath = filepath.Join(dir, fmt.Sprintf("minikube_%s_%s_%d.log", os.Args[1], hs, logIdx))
logfilePath = filepath.Join(dir, fmt.Sprintf("minikube_%s_%s_%d.log", pflag.Arg(0), hs, logIdx))
}
// if log has reached max size 1M, generate new logfile name by incrementing count
if checkLogFileMaxSize(logfilePath, 1024) {

View File

@ -151,7 +151,9 @@ func TestErrorSpam(t *testing.T) {
for _, test := range logTests {
t.Run(test.command, func(t *testing.T) {
args := []string{test.command, "-p", profile, "--log_dir", logDir}
// flags can be before subcommand
args := []string{"-p", profile, "--log_dir", logDir, test.command}
args = append(args, test.args...)
// before starting the test, ensure no other logs from the current command are written