func client() *ml.MesosClient { var host string var port = 5050 master, err := rootCmd.PersistentFlags().GetString(MasterFlag) if master == "" { if os.Getenv(EnvMesosMaster) == "" { printErr(fmt.Errorf("Must define a Master host and optional port")) os.Exit(1) } master = os.Getenv(EnvMesosMaster) // master = "internal-lt-mesos-privatee-mw3lkjkwdyni-213084364.us-west-2.elb.amazonaws.com:5050" } if strings.Contains(master, ":") { hp := strings.Split(master, ":") host = hp[0] port, err = strconv.Atoi(hp[1]) if err != nil { printErr(err) os.Exit(1) } } else { host = master } c, err := ml.NewMesosClient(host, port) if err != nil { printErr(err) os.Exit(1) } return c }
func showLogCmd(cmd *cobra.Command, args []string) { if cli.EvalPrintUsage(Usage(cmd), args, 1) { return } host := getMesosHost() logType := ml.STDOUT if stderr, _ := cmd.Flags().GetBool(STDERR_FLAG); stderr { logType = ml.STDERR } c, _ := ml.NewMesosClient(host, 5050) appId := getMesosAppIdentifier(cmd, c, args[0]) if follow, _ := cmd.Flags().GetBool(FOLLOW_FLAG); follow { duration, _ := cmd.Flags().GetInt(POLL_FLAG) if duration < 1 { duration = 5 } if err := c.TailLog(appId, logType, duration); err != nil { log.Fatal(err) } return } logs, err := c.GetLog(appId, logType, "") if err != nil { log.Fatal(err) } showBreaks := len(logs) > 1 for _, log := range logs { if showBreaks { fmt.Printf("\n::: [ %s - Logs For: %s ] ::: \n", args[0], log.TaskID) } fmt.Printf("%s\n", log.Log) if showBreaks { fmt.Printf("\n!!! [ %s - End Logs For: %s ] !!! \n", args[0], log.TaskID) } } }