您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

67 行
1.8 KiB

  1. // Copyright 2016 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package logadmin_test
  15. import (
  16. "context"
  17. "fmt"
  18. "time"
  19. "cloud.google.com/go/logging/logadmin"
  20. "google.golang.org/api/iterator"
  21. )
  22. func ExampleClient_Entries() {
  23. ctx := context.Background()
  24. client, err := logadmin.NewClient(ctx, "my-project")
  25. if err != nil {
  26. // TODO: Handle error.
  27. }
  28. it := client.Entries(ctx, logadmin.Filter(`logName = "projects/my-project/logs/my-log"`))
  29. _ = it // TODO: iterate using Next or iterator.Pager.
  30. }
  31. func ExampleFilter_timestamp() {
  32. // This example demonstrates how to list the last 24 hours of log entries.
  33. ctx := context.Background()
  34. client, err := logadmin.NewClient(ctx, "my-project")
  35. if err != nil {
  36. // TODO: Handle error.
  37. }
  38. oneDayAgo := time.Now().Add(-24 * time.Hour)
  39. t := oneDayAgo.Format(time.RFC3339) // Logging API wants timestamps in RFC 3339 format.
  40. it := client.Entries(ctx, logadmin.Filter(fmt.Sprintf(`timestamp > "%s"`, t)))
  41. _ = it // TODO: iterate using Next or iterator.Pager.
  42. }
  43. func ExampleEntryIterator_Next() {
  44. ctx := context.Background()
  45. client, err := logadmin.NewClient(ctx, "my-project")
  46. if err != nil {
  47. // TODO: Handle error.
  48. }
  49. it := client.Entries(ctx)
  50. for {
  51. entry, err := it.Next()
  52. if err == iterator.Done {
  53. break
  54. }
  55. if err != nil {
  56. // TODO: Handle error.
  57. }
  58. fmt.Println(entry)
  59. }
  60. }