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 (GA)
Stackdriver Logging API: Writes log entries and manages your Stackdriver Logging configuration.
Quick Start
In order to use this library, you first need to go through the following steps:
- Select or create a Cloud Platform project.
- Enable the Stackdriver Logging API.
- 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
- Read the Stackdriver Logging API Product documentation to learn more about the product and see How-to Guides.
- View this repository's main README to see the full list of Cloud APIs that we cover.
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.5.1".freeze
Class Method Summary collapse
-
.configure {|Google::Cloud.configure.logging| ... } ⇒ Google::Cloud::Config
Configure the Google::Cloud::Logging::Middleware when used in a Rack-based application.
-
.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.
Class Method Details
.configure {|Google::Cloud.configure.logging| ... } ⇒ Google::Cloud::Config
Configure the Google::Cloud::Logging::Middleware when used in a Rack-based application.
The following Stackdriver Logging configuration parameters are supported:
project_id
- (String) Project identifier for the Stackdriver Logging service you are connecting to. (The parameterproject
is considered deprecated, but may also be 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) (The parameterkeyfile
is considered deprecated, but may also be used.)scope
- (String, Array) The OAuth 2.0 scopes controlling the set of resources and operations that the connection can access. timeout
- (Integer) Default timeout to use in requests.client_config
- (Hash) A hash of values to override the default behavior of the API client.log_name
- (String) Name of the application log file. Default:"ruby_app_log"
log_name_map
- (Hash) Map specific request routes to other log. Default:{ "/_ah/health" => "ruby_health_check_log" }
monitored_resource.type
(String) Resource type name. See full list. Self discovered on GCP.monitored_resource.labels
-(Hash) Resource labels. See full list. Self discovered on GCP.labels
- (Hash) User defined labels. AHash
of label names to string label values or callables/Proc
which are functions of the Rack environment.
See the Configuration Guide for full configuration parameters.
491 492 493 494 495 |
# File 'lib/google/cloud/logging.rb', line 491 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.
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 |
# File 'lib/google/cloud/logging.rb', line 428 def self.new project_id: nil, credentials: nil, scope: nil, timeout: nil, client_config: nil, project: nil, keyfile: nil project_id ||= (project || default_project_id) project_id = project_id.to_s # Always cast to a string raise ArgumentError, "project_id is missing" if project_id.empty? scope ||= configure.scope timeout ||= configure.timeout client_config ||= configure.client_config credentials ||= (keyfile || default_credentials(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 |