Skip to content

Commit

Permalink
add --audit flag to minikube logs command
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwinWalela committed Apr 20, 2022
1 parent 4c72578 commit 4684903
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 10 additions & 2 deletions cmd/minikube/cmd/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ var (
showProblems bool
// fileOutput is where to write logs to. If omitted, writes to stdout.
fileOutput string
// auditLogs only shows the audit logs
auditLogs bool
)

// logsCmd represents the logs command
Expand All @@ -73,7 +75,13 @@ var logsCmd = &cobra.Command{
exit.Error(reason.Usage, "Failed to create file", err)
}
}

if auditLogs {
err := logs.OutputAudit(numberOfLines)
if err != nil {
klog.Errorf("failed to output audit logs: %v", err)
}
return
}
logs.OutputOffline(numberOfLines, logOutput)

if shouldSilentFail() {
Expand All @@ -91,7 +99,6 @@ var logsCmd = &cobra.Command{
if err != nil {
exit.Error(reason.InternalNewRuntime, "Unable to get runtime", err)
}

if followLogs {
err := logs.Follow(cr, bs, *co.Config, co.CP.Runner, logOutput)
if err != nil {
Expand Down Expand Up @@ -142,4 +149,5 @@ func init() {
logsCmd.Flags().IntVarP(&numberOfLines, "length", "n", 60, "Number of lines back to go within the log")
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")
}
4 changes: 2 additions & 2 deletions pkg/minikube/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func Output(r cruntime.Manager, bs bootstrapper.Bootstrapper, cfg config.Cluster
}

// outputAudit displays the audit logs.
func outputAudit(lines int) error {
func OutputAudit(lines int) error {
out.Styled(style.Empty, "")
out.Styled(style.Empty, "==> Audit <==")
r, err := audit.Report(lines)
Expand Down Expand Up @@ -252,7 +252,7 @@ func OutputOffline(lines int, logOutput *os.File) {
defer out.SetOutFile(os.Stdout)
out.SetErrFile(logOutput)
defer out.SetErrFile(os.Stderr)
if err := outputAudit(lines); err != nil {
if err := OutputAudit(lines); err != nil {
klog.Errorf("failed to output audit logs: %v", err)
}
if err := outputLastStart(); err != nil {
Expand Down

0 comments on commit 4684903

Please sign in to comment.