mirror of
https://github.com/zrepl/zrepl.git
synced 2025-06-20 01:37:45 +02:00
control status command: only show verbose logs on user request
This commit is contained in:
parent
6f68c98c16
commit
787675aee8
@ -40,9 +40,9 @@ var controlVersionCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var controlStatusCmdArgs struct {
|
var controlStatusCmdArgs struct {
|
||||||
format string
|
format string
|
||||||
alwaysShowLogs bool
|
level logger.Level
|
||||||
onlyShowJob string
|
onlyShowJob string
|
||||||
}
|
}
|
||||||
|
|
||||||
var controlStatusCmd = &cobra.Command{
|
var controlStatusCmd = &cobra.Command{
|
||||||
@ -58,7 +58,8 @@ func init() {
|
|||||||
controlCmd.AddCommand(controlVersionCmd)
|
controlCmd.AddCommand(controlVersionCmd)
|
||||||
controlCmd.AddCommand(controlStatusCmd)
|
controlCmd.AddCommand(controlStatusCmd)
|
||||||
controlStatusCmd.Flags().StringVar(&controlStatusCmdArgs.format, "format", "human", "output format (human|raw)")
|
controlStatusCmd.Flags().StringVar(&controlStatusCmdArgs.format, "format", "human", "output format (human|raw)")
|
||||||
controlStatusCmd.Flags().BoolVar(&controlStatusCmdArgs.alwaysShowLogs, "always-show-logs", false, "always show logs, even if no error occured")
|
controlStatusCmdArgs.level = logger.Warn
|
||||||
|
controlStatusCmd.Flags().Var(&controlStatusCmdArgs.level, "level", "minimum log level to show")
|
||||||
}
|
}
|
||||||
|
|
||||||
func controlHttpClient() (client http.Client, err error) {
|
func controlHttpClient() (client http.Client, err error) {
|
||||||
@ -283,25 +284,26 @@ func doControlStatusCmd(cmd *cobra.Command, args []string) {
|
|||||||
informAboutError = informAboutError || task.MaxLogLevel >= logger.Warn
|
informAboutError = informAboutError || task.MaxLogLevel >= logger.Warn
|
||||||
}
|
}
|
||||||
|
|
||||||
showLog := informAboutError || controlStatusCmdArgs.alwaysShowLogs
|
sort.Slice(jobLogEntries, func(i, j int) bool {
|
||||||
|
return jobLogEntries[i].Time.Before(jobLogEntries[j].Time)
|
||||||
if showLog {
|
})
|
||||||
sort.Slice(jobLogEntries, func(i, j int) bool {
|
if informAboutError {
|
||||||
return jobLogEntries[i].Time.Before(jobLogEntries[j].Time)
|
fmt.Println(" WARNING: Some tasks encountered problems since the last time they left idle state:")
|
||||||
})
|
fmt.Println(" check the logs below or your log file for more information.")
|
||||||
if informAboutError {
|
fmt.Println(" Use the --level flag if you need debug information.")
|
||||||
fmt.Println(" WARNING: Some tasks encountered problems since the last time they left idle state:")
|
|
||||||
fmt.Println(" check the logs below or your log file for more information.")
|
|
||||||
}
|
|
||||||
for _, e := range jobLogEntries {
|
|
||||||
formatted, err := formatter.Format(&e)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
fmt.Printf(" %s\n", string(formatted))
|
|
||||||
}
|
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
}
|
}
|
||||||
|
for _, e := range jobLogEntries {
|
||||||
|
if e.Level < controlStatusCmdArgs.level {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
formatted, err := formatter.Format(&e)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
fmt.Printf(" %s\n", string(formatted))
|
||||||
|
}
|
||||||
|
fmt.Println()
|
||||||
|
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user