Then google-cloud-logging gem provides a Rack Middleware class that can easily
integrate with Rack based application frameworks, such as Rails and Sinatra.
When enabled, it sets an instance of Google::Cloud::Logging::Logger as the
default Rack or Rails logger. Then all consequent log entries will be submitted
to the Stackdriver Logging service.
On top of that, the google-cloud-logging also implements a Railtie class that
automatically enables the Rack Middleware in Rails applications when used.
Configuration
The default configuration enables Stackdriver instrumentation features to run
on Google Cloud Platform. You can easily configure the instrumentation library
if you want to run on a non Google Cloud environment or you want to customize
the default behavior.
To install application instrumentation in your Ruby on Rails app, add this
gem, google-cloud-logging, to your Gemfile and update your bundle. Then
add the following line to your config/application.rb file:
require"google/cloud/logging/rails"
This will load a Railtie that automatically integrates with the Rails
framework by injecting a Rack middleware.
Using instrumentation with Sinatra
To install application instrumentation in your Sinatra app, add this gem,
google-cloud-logging, to your Gemfile and update your bundle. Then add
the following lines to your main application Ruby file:
This will install the logging middleware in your application.
Using instrumentation with other Rack-based frameworks
To install application instrumentation in an app using another Rack-based
web framework, add this gem, google-cloud-logging, to your Gemfile and
update your bundle. Then add install the logging middleware in your
middleware stack. In most cases, this means adding these lines to your
config.ru Rack configuration file:
Some web frameworks have an alternate mechanism for modifying the
middleware stack. Consult your web framework's documentation for more
information.
The Stackdriver diagnostics suite
The google-cloud-logging library is part of the Stackdriver diagnostics suite,
which also includes error reporting, tracing analysis, and real-time debugger.
If you include the stackdriver gem in your Gemfile, this logging library will
be included automatically. In addition, if you include the stackdriver
gem in an application using Ruby On Rails, the Railties will be installed
automatically. See the documentation for the "stackdriver" gem
for more details.
[[["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,["Version latestkeyboard_arrow_down\n\n- [2.6.0 (latest)](/ruby/docs/reference/google-cloud-logging/latest/INSTRUMENTATION)\n- [2.5.0](/ruby/docs/reference/google-cloud-logging/2.5.0/INSTRUMENTATION)\n- [2.4.0](/ruby/docs/reference/google-cloud-logging/2.4.0/INSTRUMENTATION)\n- [2.3.3](/ruby/docs/reference/google-cloud-logging/2.3.3/INSTRUMENTATION)\n- [2.2.2](/ruby/docs/reference/google-cloud-logging/2.2.2/INSTRUMENTATION) \n\nStackdriver Logging Instrumentation\n===================================\n\nThen google-cloud-logging gem provides a Rack Middleware class that can easily\nintegrate with Rack based application frameworks, such as Rails and Sinatra.\nWhen enabled, it sets an instance of Google::Cloud::Logging::Logger as the\ndefault Rack or Rails logger. Then all consequent log entries will be submitted\nto the Stackdriver Logging service.\n\nOn top of that, the google-cloud-logging also implements a Railtie class that\nautomatically enables the Rack Middleware in Rails applications when used.\n\nConfiguration\n-------------\n\nThe default configuration enables Stackdriver instrumentation features to run\non Google Cloud Platform. You can easily configure the instrumentation library\nif you want to run on a non Google Cloud environment or you want to customize\nthe default behavior.\n\nSee the\n[Configuration Guide](https://googleapis.dev/ruby/stackdriver/latest/file.INSTRUMENTATION_CONFIGURATION.html)\nfor full configuration parameters.\n\nUsing instrumentation with Ruby on Rails\n----------------------------------------\n\nTo install application instrumentation in your Ruby on Rails app, add this\ngem, `google-cloud-logging`, to your Gemfile and update your bundle. Then\nadd the following line to your `config/application.rb` file: \n\n```ruby\nrequire \"google/cloud/logging/rails\"\n```\n\nThis will load a Railtie that automatically integrates with the Rails\nframework by injecting a Rack middleware.\n\nUsing instrumentation with Sinatra\n----------------------------------\n\nTo install application instrumentation in your Sinatra app, add this gem,\n`google-cloud-logging`, to your Gemfile and update your bundle. Then add\nthe following lines to your main application Ruby file: \n\n```ruby\nrequire \"google/cloud/logging\"\nuse Google::Cloud::Logging::Middleware\n```\n\nThis will install the logging middleware in your application.\n\n### Using instrumentation with other Rack-based frameworks\n\nTo install application instrumentation in an app using another Rack-based\nweb framework, add this gem, `google-cloud-logging`, to your Gemfile and\nupdate your bundle. Then add install the logging middleware in your\nmiddleware stack. In most cases, this means adding these lines to your\n`config.ru` Rack configuration file: \n\n```ruby\nrequire \"google/cloud/logging\"\nuse Google::Cloud::Logging::Middleware\n```\n\nSome web frameworks have an alternate mechanism for modifying the\nmiddleware stack. Consult your web framework's documentation for more\ninformation.\n\n### The Stackdriver diagnostics suite\n\nThe google-cloud-logging library is part of the Stackdriver diagnostics suite,\nwhich also includes error reporting, tracing analysis, and real-time debugger.\nIf you include the `stackdriver` gem in your Gemfile, this logging library will\nbe included automatically. In addition, if you include the `stackdriver`\ngem in an application using Ruby On Rails, the Railties will be installed\nautomatically. See the documentation for the \"stackdriver\" gem\nfor more details."]]