Module: Google::Cloud::Logging

Defined in:
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/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/v2/doc/overview.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,
lib/google/cloud/logging/v2/config_service_v2_client.rb,
lib/google/cloud/logging/v2/logging_service_v2_client.rb,
lib/google/cloud/logging/v2/metrics_service_v2_client.rb

Overview

Ruby Client for Stackdriver Logging API (Alpha)

Stackdriver Logging API: The Stackdriver Logging API lets you write log entries and manage your logs, log sinks and logs-based metrics.

Quick Start

In order to use this library, you first need to go through the following steps:

  1. Select or create a Cloud Platform project.
  2. Enable the Stackdriver Logging API.
  3. Setup Authentication.

Installation

$ gem install google-cloud-logging

Preview

LoggingServiceV2Client

require "google/cloud/logging"

logging_service_v2_client = Google::Cloud::Logging::Logging.new
formatted_log_name = Google::Cloud::Logging::V2::LoggingServiceV2Client.log_path(project_id, "test-" + Time.new.to_i.to_s)
resource = {}
labels = {}
entries = []
response = logging_service_v2_client.write_log_entries(entries, log_name: formatted_log_name, resource: resource, labels: labels)

Next Steps

Defined Under Namespace

Modules: V2 Classes: AsyncWriter, Credentials, Entry, Log, Logger, Metric, Middleware, Project, Railtie, Resource, ResourceDescriptor, Sink

Constant Summary collapse

DEFAULT_LOG_NAME =

Default log name to be used for Stackdriver Logging

Middleware::DEFAULT_LOG_NAME
VERSION =
"1.3.1"

Class Method Summary collapse

Class Method Details

.configure {|Google::Cloud.configure.logging| ... } ⇒ Stackdriver::Core::Configuration

Configure the Google::Cloud::Logging::Middleware when used in a Rack-based application.

See the Configuration Guide for full configuration parameters.

Yields:

Returns:

  • (Stackdriver::Core::Configuration)

    The configuration object the Google::Cloud::Logging module uses.



425
426
427
428
429
# File 'lib/google/cloud/logging.rb', line 425

def self.configure
  yield Google::Cloud.configure.logging if block_given?

  Google::Cloud.configure.logging
end

.new(project_id: nil, credentials: nil, scope: nil, timeout: nil, client_config: nil, project: nil, keyfile: 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"

logging = Google::Cloud::Logging.new

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

Parameters:

  • project_id (String)

    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)

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

  • scope (String, Array<String>)

    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)

    Default timeout to use in requests. Optional.

  • client_config (Hash)

    A hash of values to override the default behavior of the API client. Optional.

  • project (String)

    Alias for the project_id argument. Deprecated.

  • keyfile (String)

    Alias for the credentials argument. Deprecated.

Returns:



397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
# File 'lib/google/cloud/logging.rb', line 397

def self.new project_id: nil, credentials: nil, scope: nil, timeout: nil,
             client_config: nil, project: nil, keyfile: nil
  project_id ||= (project || Logging::Project.default_project_id)
  project_id = project_id.to_s # Always cast to a string
  fail ArgumentError, "project_id is missing" if project_id.empty?

  credentials ||= (keyfile || Logging::Credentials.default(scope: scope))
  unless credentials.is_a? Google::Auth::Credentials
    credentials = Logging::Credentials.new credentials, scope: scope
  end

  Logging::Project.new(
    Logging::Service.new(
      project_id, credentials, timeout: timeout,
                               client_config: client_config))
end