Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new flag --last-start-only to only show last start logs #15770

Merged
merged 6 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cmd/minikube/cmd/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ var (
fileOutput string
// auditLogs only shows the audit logs
auditLogs bool
// lastStartOnly shows logs from last start
lastStartOnly bool
)

// logsCmd represents the logs command
Expand All @@ -75,6 +77,13 @@ var logsCmd = &cobra.Command{
exit.Error(reason.Usage, "Failed to create file", err)
}
}
if lastStartOnly {
err := logs.OutputLastStart()
if err != nil {
klog.Errorf("failed to output last start logs: %V", err)
nickmancari marked this conversation as resolved.
Show resolved Hide resolved
}
return
}
if auditLogs {
err := logs.OutputAudit(numberOfLines)
if err != nil {
Expand Down Expand Up @@ -150,4 +159,5 @@ func init() {
logsCmd.Flags().StringVar(&nodeName, "node", "", "The node to get logs from. Defaults to the primary control plane.")
logsCmd.Flags().StringVar(&fileOutput, "file", "", "If present, writes to the provided file instead of stdout.")
logsCmd.Flags().BoolVar(&auditLogs, "audit", false, "Show only the audit logs")
logsCmd.Flags().BoolVar(&lastStartOnly, "last-start-only", false, "Show logs from last start.")
nickmancari marked this conversation as resolved.
Show resolved Hide resolved
}
4 changes: 2 additions & 2 deletions pkg/minikube/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func OutputAudit(lines int) error {
}

// outputLastStart outputs the last start logs.
func outputLastStart() error {
func OutputLastStart() error {
out.Styled(style.Empty, "")
out.Styled(style.Empty, "==> Last Start <==")
fp := localpath.LastStartLog()
Expand Down Expand Up @@ -256,7 +256,7 @@ func OutputOffline(lines int, logOutput *os.File) {
if err := OutputAudit(lines); err != nil {
klog.Errorf("failed to output audit logs: %v", err)
}
if err := outputLastStart(); err != nil {
if err := OutputLastStart(); err != nil {
klog.Errorf("failed to output last start logs: %v", err)
}

Expand Down