Esempio n. 1
0
func getLogsWithFollow(c v1alpha.PublicAPIClient, p *v1alpha.Pod) {
	if len(p.Apps) == 0 {
		fmt.Printf("Pod %q has no apps\n", p.Id)
		return
	}

	logsResp, err := c.GetLogs(context.Background(), &v1alpha.GetLogsRequest{
		PodId:   p.Id,
		Follow:  true,
		AppName: p.Apps[0].Name,
	})
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	for {
		logsRecvResp, err := logsResp.Recv()
		if err == io.EOF {
			return
		}

		if err != nil {
			fmt.Println(err)
			return
		}

		for _, l := range logsRecvResp.Lines {
			fmt.Println(l)
		}
	}
}
Esempio n. 2
0
func getLogsWithoutFollow(c v1alpha.PublicAPIClient, p *v1alpha.Pod) {
	if len(p.Apps) == 0 {
		fmt.Printf("Pod %q has no apps\n", p.Id)
		return
	}

	logsResp, err := c.GetLogs(context.Background(), &v1alpha.GetLogsRequest{
		PodId:     p.Id,
		Follow:    false,
		AppName:   p.Apps[0].Name,
		SinceTime: time.Now().Add(-time.Second * 5).Unix(),
		Lines:     10,
	})

	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	logsRecvResp, err := logsResp.Recv()

	if err == io.EOF {
		return
	}

	if err != nil {
		fmt.Println(err)
		return
	}

	for _, l := range logsRecvResp.Lines {
		fmt.Println(l)
	}
}