add --audit flag to minikube logs command

pull/13991/head
edwinwalela 2022-04-20 20:23:07 +03:00
parent 4c725782c9
commit 46849037b2
2 changed files with 12 additions and 4 deletions

View File

@ -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
@ -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() {
@ -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 {
@ -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")
}

View File

@ -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)
@ -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 {