Skip to content

Instantly share code, notes, and snippets.

@yifan-gu
Created June 10, 2016 01:33
Show Gist options
  • Save yifan-gu/220c8458a2b28f91f166daabc06f5589 to your computer and use it in GitHub Desktop.
Save yifan-gu/220c8458a2b28f91f166daabc06f5589 to your computer and use it in GitHub Desktop.
testlog.go
package main
import (
"flag"
"fmt"
"io"
"os"
"github.com/coreos/rkt/api/v1alpha"
"golang.org/x/net/context"
"google.golang.org/grpc"
)
func main() {
lines := flag.Int("lines", 0, "tail lines")
flag.Parse()
conn, err := grpc.Dial("localhost:15441", grpc.WithInsecure())
if err != nil {
fmt.Println(err)
os.Exit(1)
}
c := v1alpha.NewPublicAPIClient(conn)
defer conn.Close()
podResp, err := c.ListPods(context.Background(), &v1alpha.ListPodsRequest{})
if err != nil {
fmt.Println(err)
os.Exit(1)
}
for _, p := range podResp.Pods {
fmt.Printf("Pod %q state %q.\n", p.Id, p.State)
logsResp, err := c.GetLogs(context.Background(), &v1alpha.GetLogsRequest{
PodId: p.Id,
Follow: false,
AppName: p.Apps[0].Name,
Lines: int32(*lines),
})
if err != nil {
fmt.Println(err)
os.Exit(1)
}
for {
resp, err := logsResp.Recv()
if err == io.EOF {
fmt.Println("EOF")
break
}
if err != nil {
fmt.Println(err)
os.Exit(1)
}
for _, l := range resp.Lines {
fmt.Println(l)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment