func handleEntries(w http.ResponseWriter, r *http.Request) { ctx := context.Background() filter := fmt.Sprintf(`logName = "projects/%s/logs/testlog"`, *projectID) it := client.Entries(ctx, logadmin.Filter(filter)) var entries []*logging.Entry nextTok, err := iterator.NewPager(it, 5, r.URL.Query().Get("pageToken")).NextPage(&entries) if err != nil { http.Error(w, fmt.Sprintf("problem getting the next page: %v", err), http.StatusInternalServerError) return } data := struct { Entries []*logging.Entry Next string }{ entries, nextTok, } var buf bytes.Buffer if err := pageTemplate.Execute(&buf, data); err != nil { http.Error(w, fmt.Sprintf("problem executing page template: %v", err), http.StatusInternalServerError) } if _, err := buf.WriteTo(w); err != nil { log.Printf("writing response: %v", err) } }
func ExampleClient_Entries() { ctx := context.Background() client, err := logadmin.NewClient(ctx, "my-project") if err != nil { // TODO: Handle error. } it := client.Entries(ctx, logadmin.Filter(`logName = "projects/my-project/logs/my-log"`)) _ = it // TODO: iterate using Next or iterator.Pager. }
func ExampleFilter_timestamp() { // This example demonstrates how to list the last 24 hours of log entries. ctx := context.Background() client, err := logadmin.NewClient(ctx, "my-project") if err != nil { // TODO: Handle error. } oneDayAgo := time.Now().Add(-24 * time.Hour) t := oneDayAgo.Format(time.RFC3339) // Logging API wants timestamps in RFC 3339 format. it := client.Entries(ctx, logadmin.Filter(fmt.Sprintf(`timestamp > "%s"`, t))) _ = it // TODO: iterate using Next or iterator.Pager. }
func countLogEntries(ctx context.Context, filter string) int { it := aclient.Entries(ctx, logadmin.Filter(filter)) n := 0 for { _, err := it.Next() if err == iterator.Done { return n } if err != nil { log.Fatalf("counting log entries: %v", err) } n++ } }
func allTestLogEntries(ctx context.Context) ([]*logging.Entry, error) { var es []*logging.Entry it := aclient.Entries(ctx, logadmin.Filter(testFilter)) for { e, err := cleanNext(it) switch err { case nil: es = append(es, e) case iterator.Done: return es, nil default: return nil, err } } }