Reference documentation and code samples for the Cloud Logging API class Google::Cloud::Logging::Railtie.
Railtie
Adds the Middleware to Rack in a Rails
environment. The middleware will set env['rack.logger']
to a
Logger instance to be used by the Rails
application.
The middleware is loaded only when certain conditions are met. These
conditions are when the configuration
Google::Cloud.configure.use_logging
(also available as
Rails.application.config.google_cloud.use_logging
for a Rails
application) is set to true
, or, if the configuration is left unset
but Rails.env.production?
is true
.
When loaded, the Middleware will be inserted
before the Rails::Rack::Logger Middleware
, which allows it to set the
env['rack.logger']
in place of Rails's default logger.
See the Configuration
Guide
on how to configure the Railtie and Middleware.
Inherits
- Rails::Railtie
Methods
.set_default_logger
def self.set_default_logger()
This should be called once the application determines that it is safe
to start background threads and open gRPC connections. It informs the
middleware system that it is safe to use Google Cloud Logging. This is
called during Rails initialization when the
set_default_logger_on_rails_init
configuration is set.
Generally, this matters if the application forks worker processes;
this method should be called only after workers are forked, since
threads and network connections interact badly with fork. For example,
when running Puma in clustered
mode, this method should
be called in an on_worker_boot
block.
If the application does no forking, this method can be called any time
early in the application initialization process. Or by setting the
set_default_logger_on_rails_init
configuration.
If the set_default_logger_on_rails_init
configuration is not set,
and Railtie.set_default_logger is not called in a post-fork hook,
the default Rails logger object will not be set to use the Google
Cloud Logging Logger object. For best results, an application should
call this method at the appropriate time, such as a post-fork hook.