Module: Google::Cloud

Defined in:
lib/google-cloud-logging.rb,
lib/google/cloud/logging.rb,
lib/google/cloud/logging/sink.rb,
lib/google/cloud/logging/entry.rb,
lib/google/cloud/logging/rails.rb,
lib/google/cloud/logging/errors.rb,
lib/google/cloud/logging/logger.rb,
lib/google/cloud/logging/metric.rb,
lib/google/cloud/logging/convert.rb,
lib/google/cloud/logging/project.rb,
lib/google/cloud/logging/service.rb,
lib/google/cloud/logging/version.rb,
lib/google/cloud/logging/log/list.rb,
lib/google/cloud/logging/resource.rb,
lib/google/cloud/logging/sink/list.rb,
lib/google/cloud/logging/entry/list.rb,
lib/google/cloud/logging/middleware.rb,
lib/google/cloud/logging/credentials.rb,
lib/google/cloud/logging/metric/list.rb,
lib/google/cloud/logging/async_writer.rb,
lib/google/cloud/logging/entry/operation.rb,
lib/google/cloud/logging/entry/http_request.rb,
lib/google/cloud/logging/resource_descriptor.rb,
lib/google/cloud/logging/entry/source_location.rb,
lib/google/cloud/logging/resource_descriptor/list.rb

Defined Under Namespace

Modules: Logging

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.logging(project_id = nil, credentials = nil, scope: nil, timeout: nil) ⇒ Google::Cloud::Logging::Project

Creates a new object for connecting to the Stackdriver Logging service. Each call creates a new connection.

For more information on connecting to Google Cloud see the Authentication Guide.

Examples:

require "google/cloud"

logging = Google::Cloud.logging

entries = logging.entries
entries.each do |e|
  puts "[#{e.timestamp}] #{e.log_name} #{e.payload.inspect}"
end

Parameters:

  • project_id (String) (defaults to: nil)

    Project identifier for the Stackdriver Logging service you are connecting to. If not present, the default project for the credentials is used.

  • credentials (String, Hash, Google::Auth::Credentials) (defaults to: nil)

    The path to the keyfile as a String, the contents of the keyfile as a Hash, or a Google::Auth::Credentials object. (See Google::Cloud::Logging::Credentials)

  • scope (String, Array<String>) (defaults to: nil)

    The OAuth 2.0 scopes controlling the set of resources and operations that the connection can access. See Using OAuth 2.0 to Access Google APIs.

    The default scope is:

    • https://www.googleapis.com/auth/logging.admin
  • timeout (Integer) (defaults to: nil)

    Default timeout to use in requests. Optional.

Returns:



109
110
111
112
113
114
# File 'lib/google-cloud-logging.rb', line 109

def self.logging project_id = nil, credentials = nil, scope: nil, timeout: nil
  require "google/cloud/logging"
  Google::Cloud::Logging.new project_id: project_id,
                             credentials: credentials,
                             scope: scope, timeout: timeout
end

Instance Method Details

#logging(scope: nil, timeout: nil) ⇒ Google::Cloud::Logging::Project

Creates a new object for connecting to the Stackdriver Logging service. Each call creates a new connection.

For more information on connecting to Google Cloud see the Authentication Guide.

Examples:

require "google/cloud"

gcloud = Google::Cloud.new
logging = gcloud.logging

entries = logging.entries
entries.each do |e|
  puts "[#{e.timestamp}] #{e.log_name} #{e.payload.inspect}"
end

The default scope can be overridden with the scope option:

require "google/cloud"

gcloud  = Google::Cloud.new
platform_scope = "https://www.googleapis.com/auth/cloud-platform"
logging = gcloud.logging scope: platform_scope

Parameters:

  • scope (String, Array<String>) (defaults to: nil)

    The OAuth 2.0 scopes controlling the set of resources and operations that the connection can access. See Using OAuth 2.0 to Access Google APIs.

    The default scope is:

    • https://www.googleapis.com/auth/logging.admin
  • timeout (Integer) (defaults to: nil)

    Default timeout to use in requests. Optional.

Returns:



67
68
69
70
71
# File 'lib/google-cloud-logging.rb', line 67

def logging scope: nil, timeout: nil
  timeout ||= @timeout
  Google::Cloud.logging @project, @keyfile, scope:   scope,
                                            timeout: timeout
end