func getEntries(adminClient *logadmin.Client, projID string) ([]*logging.Entry, error) { ctx := context.Background() // [START list_log_entries] var entries []*logging.Entry const name = "log-example" iter := adminClient.Entries(ctx, // Only get entries from the log-example log. logadmin.Filter(fmt.Sprintf(`logName = "projects/%s/logs/%s"`, projID, name)), // Get most recent entries first. logadmin.NewestFirst(), ) // Fetch the most recent 20 entries. for len(entries) < 20 { entry, err := iter.Next() if err == iterator.Done { return entries, nil } if err != nil { return nil, err } entries = append(entries, entry) } return entries, nil // [END list_log_entries] }
func deleteSink(client *logadmin.Client) error { // [START delete_log_sink] ctx := context.Background() if err := client.DeleteSink(ctx, "severe-errors-to-gcs"); err != nil { return err } // [END delete_log_sink] return nil }
func deleteLog(adminClient *logadmin.Client) error { ctx := context.Background() // [START delete_log] const name = "log-example" if err := adminClient.DeleteLog(ctx, name); err != nil { return err } // [END delete_log] return nil }
func updateSink(client *logadmin.Client) error { // [START update_log_sink] ctx := context.Background() _, err := client.UpdateSink(ctx, &logadmin.Sink{ ID: "severe-errors-to-gcs", Destination: "storage.googleapis.com/logsinks-new-bucket", Filter: "severity >= INFO", }) // [END update_log_sink] return err }
func listSinks(client *logadmin.Client) ([]string, error) { // [START list_log_sinks] ctx := context.Background() var sinks []string it := client.Sinks(ctx) for { sink, err := it.Next() if err == iterator.Done { break } if err != nil { return nil, err } sinks = append(sinks, sink.ID) } // [END list_log_sinks] return sinks, nil }