From 58aadf1636a9f36198b94117cfb5157edba1f8bf Mon Sep 17 00:00:00 2001 From: mattisafur <46404761+mattisafur@users.noreply.github.com> Date: Fri, 20 Dec 2024 13:56:07 +0200 Subject: [PATCH] fixed logs issue #19931 --- cmd/minikube/cmd/logs.go | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/cmd/minikube/cmd/logs.go b/cmd/minikube/cmd/logs.go index e05638b2458f..5bf3010ef3c0 100644 --- a/cmd/minikube/cmd/logs.go +++ b/cmd/minikube/cmd/logs.go @@ -77,22 +77,34 @@ var logsCmd = &cobra.Command{ if err != nil { exit.Error(reason.Usage, "Failed to create file", err) } + out.SetOutFile(logOutput) + defer out.SetOutFile(os.Stdout) + out.SetErrFile(logOutput) + defer out.SetErrFile(os.Stderr) } - if lastStartOnly { - err := logs.OutputLastStart() + + switch { + case lastStartOnly: + err = logs.OutputLastStart() if err != nil { klog.Errorf("failed to output last start logs: %v", err) } - return - } - if auditLogs { - err := logs.OutputAudit(numberOfLines) + case auditLogs: + err = logs.OutputAudit(numberOfLines) if err != nil { - klog.Errorf("failed to output audit logs: %v", err) + klog.Errorf("failed to output last start logs: %v", err) } - return + default: + err = logs.OutputLastStart() + if err != nil { + klog.Errorf("failed to output last start logs: %v", err) + } + err = logs.OutputAudit(numberOfLines) + if err != nil { + klog.Errorf("failed to output last start logs: %v", err) + } + out.Styled(style.None, "") } - logs.OutputOffline(numberOfLines, logOutput) if shouldSilentFail() { return