added flag

pull/15770/head
nickmancari 2023-02-01 15:34:37 -06:00
parent 46e23cef59
commit 1db52e77b4
2 changed files with 11 additions and 2 deletions

View File

@ -52,6 +52,8 @@ var (
fileOutput string fileOutput string
// auditLogs only shows the audit logs // auditLogs only shows the audit logs
auditLogs bool auditLogs bool
// lastStartOnly shows logs from last start
lastStartOnly bool
) )
// logsCmd represents the logs command // logsCmd represents the logs command
@ -111,6 +113,12 @@ var logsCmd = &cobra.Command{
logs.OutputProblems(problems, numberOfProblems, logOutput) logs.OutputProblems(problems, numberOfProblems, logOutput)
return return
} }
if lastStartOnly {
err := logs.OutputLastStart()
if err != nil {
klog.Errorf("failed to output last start logs: %V", err)
}
}
err = logs.Output(cr, bs, *co.Config, co.CP.Runner, numberOfLines, logOutput) err = logs.Output(cr, bs, *co.Config, co.CP.Runner, numberOfLines, logOutput)
if err != nil { if err != nil {
out.Ln("") out.Ln("")
@ -150,4 +158,5 @@ func init() {
logsCmd.Flags().StringVar(&nodeName, "node", "", "The node to get logs from. Defaults to the primary control plane.") 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().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(&auditLogs, "audit", false, "Show only the audit logs")
logsCmd.Flags().BoolVar(&lastStartOnly, "last-start-only", false, "Show logs from last start.")
} }

View File

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