Reference documentation and code samples for the Cloud Logging API module Google::Cloud::Logging.
Stackdriver Logging
The Stackdriver Logging service collects and stores logs from applications
and services on the Google Cloud Platform, giving you fine-grained,
programmatic control over your projects' logs. You can use the Stackdriver
Logging API to:
Read and filter log entries
Export your log entries to Cloud Storage, BigQuery, or Cloud Pub/Sub
Create logs-based metrics for use in Cloud Monitoring
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 parameterprojectis
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. (SeeCredentials) (The
parameterkeyfileis considered deprecated, but may also be used.)
scope- (String, Array
quota_project- (String) The project ID for a project that can be
used by client libraries for quota and billing purposes.
timeout- (Integer) Default timeout to use in requests.
endpoint- (String) Override of the endpoint host name, ornilto use the default endpoint.
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. Seefull
list.
Self discovered on GCP.
monitored_resource.labels-(Hash) Resource labels. Seefull
list.
Self discovered on GCP.
labels- (Hash) User defined labels. AHashof label names to
string label values or callables/Procwhich are functions of the
Rack environment.
set_default_logger_on_rails_init- (Boolean) Whether Google Cloud
Logging Logger should be allowed to start background threads and open
gRPC connections during Rails initialization. This should only be used
with a non-forking web server. Web servers such as Puma and Unicorn
should not set this, and instead set the Rails logger to a Google
Cloud Logging Logger object on the worker process by calling<a href="Google-Cloud-Logging-Railtie#Google__Cloud__Logging__Railtie_set_default_logger_class" title="Google::Cloud::Logging::Railtie.set_default_logger (method)">Railtie.set_default_loggerat the appropriate time, such as a
post-fork hook.
on_error- (Proc) A Proc to be run when an error is encountered
on a background thread. The Proc must take the error object as the
single argument. (SeeAsyncWriter#on_error.)
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. (SeeCredentials)
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Cloud Logging API - Module Google::Cloud::Logging (v2.6.0)\n\nVersion latestkeyboard_arrow_down\n\n- [2.6.0 (latest)](/ruby/docs/reference/google-cloud-logging/latest/Google-Cloud-Logging)\n- [2.5.0](/ruby/docs/reference/google-cloud-logging/2.5.0/Google-Cloud-Logging)\n- [2.4.0](/ruby/docs/reference/google-cloud-logging/2.4.0/Google-Cloud-Logging)\n- [2.3.3](/ruby/docs/reference/google-cloud-logging/2.3.3/Google-Cloud-Logging)\n- [2.2.2](/ruby/docs/reference/google-cloud-logging/2.2.2/Google-Cloud-Logging) \nReference documentation and code samples for the Cloud Logging API module Google::Cloud::Logging.\n\nStackdriver Logging\n-------------------\n\nThe Stackdriver Logging service collects and stores logs from applications\nand services on the Google Cloud Platform, giving you fine-grained,\nprogrammatic control over your projects' logs. You can use the Stackdriver\nLogging API to:\n\n- Read and filter log entries\n- Export your log entries to Cloud Storage, BigQuery, or Cloud Pub/Sub\n- Create logs-based metrics for use in Cloud Monitoring\n- Write log entries\n\nFor general information about Stackdriver Logging, read [Stackdriver\nLogging Documentation](https://cloud.google.com/logging/docs/).\n\nSee [Stackdriver Logging Overview](./index.html \"Stackdriver Logging Overview\").\n\nMethods\n-------\n\n### .configure\n\n def self.configure() -\u003e Google::Cloud::Config\n\nConfigure the Google::Cloud::Logging::Middleware when used in a\nRack-based application.\n\n\nThe following Stackdriver Logging configuration parameters are\nsupported:\n\n- `project_id` - (String) Project identifier for the Stackdriver Logging service you are connecting to. (The parameter `project` is considered deprecated, but may also be used.)\n- `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](/ruby/docs/reference/google-cloud-logging/latest/Google-Cloud-Logging-Credentials \"Google::Cloud::Logging::Credentials (class)\")) (The parameter `keyfile` is considered deprecated, but may also be used.)\n- `scope` - (String, Array\n- `quota_project` - (String) The project ID for a project that can be used by client libraries for quota and billing purposes.\n- `timeout` - (Integer) Default timeout to use in requests.\n- `endpoint` - (String) Override of the endpoint host name, or `nil` to use the default endpoint.\n- `log_name` - (String) Name of the application log file. Default: `\"ruby_app_log\"`\n- `log_name_map` - (Hash) Map specific request routes to other log. Default: `{ \"/`*ah/health\" =\u003e \"ruby_health_check_log\" }*\n- `monitored_resource.type` (String) Resource type name. See [full\n list](https://cloud.google.com/logging/docs/api/v2/resource-list). Self discovered on GCP.\n- `monitored_resource.labels` -(Hash) Resource labels. See [full\n list](https://cloud.google.com/logging/docs/api/v2/resource-list). Self discovered on GCP.\n- `labels` - (Hash) User defined labels. A `Hash` of label names to string label values or callables/`Proc` which are functions of the Rack environment.\n- `set_default_logger_on_rails_init` - (Boolean) Whether Google Cloud Logging Logger should be allowed to start background threads and open gRPC connections during Rails initialization. This should only be used with a non-forking web server. Web servers such as Puma and Unicorn should not set this, and instead set the Rails logger to a Google Cloud Logging Logger object on the worker process by calling \\\u003ca href=\"Google-Cloud-Logging-Railtie#Google__Cloud__Logging__Railtie_set_default_logger_class\" title=\"Google::Cloud::Logging::Railtie.set_default_logger (method)\"\\\u003eRailtie.set_default_logger at the appropriate time, such as a post-fork hook.\n- `on_error` - (Proc) A Proc to be run when an error is encountered on a background thread. The Proc must take the error object as the single argument. (See [AsyncWriter#on_error](/ruby/docs/reference/google-cloud-logging/latest/Google-Cloud-Logging-AsyncWriter#Google__Cloud__Logging__AsyncWriter_on_error_instance_ \"Google::Cloud::Logging::AsyncWriter#on_error (method)\").)\n\n\u003cbr /\u003e\n\nSee the [Configuration\nGuide](https://googleapis.dev/ruby/stackdriver/latest/file.INSTRUMENTATION_CONFIGURATION.html)\nfor full configuration parameters. \n**Yields**\n\n- (Google::Cloud.configure.logging) \n**Returns**\n\n- (Google::Cloud::Config) --- The configuration object the Google::Cloud::Logging module uses.\n\n### .new\n\n def self.new(project_id: nil, credentials: nil, scope: nil, timeout: nil, endpoint: nil, project: nil, keyfile: nil) -\u003e Google::Cloud::Logging::Project\n\nCreates a new object for connecting to the Stackdriver Logging service.\nEach call creates a new connection.\n\n\n\u003cbr /\u003e\n\nFor more information on connecting to Google Cloud see the\n[Authentication Guide](./AUTHENTICATION \"Authentication Guide\"). \n**Parameters**\n\n- **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.\n- **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 [Credentials](/ruby/docs/reference/google-cloud-logging/latest/Google-Cloud-Logging-Credentials \"Google::Cloud::Logging::Credentials (class)\"))\n- **scope** (String, Array\\\u003cString\\\u003e) *(defaults to: nil)* ---\n\n The OAuth 2.0 scopes controlling\n the set of resources and operations that the connection can access.\n See [Using OAuth 2.0 to Access Google\n APIs](https://developers.google.com/identity/protocols/OAuth2).\n\n The default scope is:\n - `https://www.googleapis.com/auth/logging.admin`\n- **timeout** (Integer) *(defaults to: nil)* --- Default timeout to use in requests. Optional.\n- **endpoint** (String) *(defaults to: nil)* --- Override of the endpoint host name. Optional. If the param is nil, uses the default endpoint.\n- **project** (String) *(defaults to: nil)* --- Alias for the `project_id` argument. Deprecated.\n- **keyfile** (String) *(defaults to: nil)* --- Alias for the `credentials` argument. Deprecated. \n**Returns**\n\n- ([Google::Cloud::Logging::Project](./Google-Cloud-Logging-Project)) \n**Raises**\n\n- (ArgumentError)\n**Example** \n\n```ruby\nrequire \"google/cloud/logging\"\n\nlogging = Google::Cloud::Logging.new\n\nentries = logging.entries\nentries.each do |e|\n puts \"[#{e.timestamp}] #{e.log_name} #{e.payload.inspect}\"\nend\n```\n\nConstants\n---------\n\n### DEFAULT_LOG_NAME\n\n**value:** Middleware::DEFAULT_LOG_NAME \nDefault log name to be used for Stackdriver Logging\n\n### VERSION\n\n**value:**\"2.6.0\".freeze"]]