Class: Gcloud::Logging::Entry::List

Inherits:
Array
  • Object
show all
Defined in:
lib/gcloud/logging/entry/list.rb

Overview

Entry::List is a special case Array with additional values.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arr = []) ⇒ List

Returns a new instance of List.



31
32
33
# File 'lib/gcloud/logging/entry/list.rb', line 31

def initialize arr = []
  super arr
end

Instance Attribute Details

#tokenObject

If not empty, indicates that there are more records that match the request and this value should be passed to continue.



27
28
29
# File 'lib/gcloud/logging/entry/list.rb', line 27

def token
  @token
end

Class Method Details

.from_grpc(grpc_list, service, projects: nil, filter: nil, order: nil, max: nil) ⇒ Object

Google::Logging::V2::ListLogEntryResponse object.



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/gcloud/logging/entry/list.rb', line 83

def self.from_grpc grpc_list, service, projects: nil, filter: nil,
                   order: nil, max: nil
  entries = new(Array(grpc_list.entries).map do |grpc_entry|
    Entry.from_grpc grpc_entry
  end)
  entries.instance_eval do
    @token = grpc_list.next_page_token
    @token = nil if @token == ""
    @service = service
    @projects = projects
    @filter = filter
    @order = order
    @max = max
  end
  entries
end

Instance Method Details

#allObject

Retrieves all log entries by repeatedly loading #next until #next? returns ‘false`. Returns the list instance for method chaining.

This method may make several API calls until all log entries are retrieved. Be sure to use as narrow a search criteria as possible. Please use with caution.

Examples:

require "gcloud"

gcloud = Gcloud.new
logging = gcloud.logging
hour_ago = (Time.now - 60*60).utc.strftime('%FT%TZ')
recent_errors = "timestamp >= \"#{hour_ago}\" severity >= ERROR"
entries = logging.entries(filter: recent_errors).all


71
72
73
74
75
76
77
78
# File 'lib/gcloud/logging/entry/list.rb', line 71

def all
  while next?
    next_records = self.next
    push(*next_records)
    self.token = next_records.token
  end
  self
end

#nextObject

Retrieve the next page of entries.



43
44
45
46
47
48
49
50
51
# File 'lib/gcloud/logging/entry/list.rb', line 43

def next
  return nil unless next?
  ensure_service!
  grpc = @service.list_entries token: token, projects: @projects,
                               filter: @filter, order: @order, max: @max
  self.class.from_grpc grpc, @service
rescue GRPC::BadStatus => e
  raise Gcloud::Error.from_error(e)
end

#next?Boolean

Whether there is a next page of entries.

Returns:

  • (Boolean)


37
38
39
# File 'lib/gcloud/logging/entry/list.rb', line 37

def next?
  !token.nil?
end