Page Summary
-
The Google Ads API Ruby library allows logging of requests, responses, and summary messages to a custom or default logger.
-
Different log levels (INFO, DEBUG, WARN) are used for successful responses, API errors, and partial failures.
-
Logging can be configured in the
google_ads_config.rbfile or by setting the logger on the client instance.
You can log requests, responses, and summary messages sent to the Google Ads API using either the default logger in the Ruby client library or your own custom Ruby logger. If no logging configuration is provided, logging is disabled by default.
Log levels
The library logs events at different log levels depending on the outcome of the API request:
| Event type | Summary log level | Full request and response log level |
|---|---|---|
| Successful API response | INFO |
DEBUG |
| API error | WARN |
INFO |
| Partial failure | None | DEBUG (partial failure details) |
Configuration
You can configure logging in your google_ads_config.rb
configuration file or programmatically at runtime.
Default logger
Set up the default logger by specifying the log_level and log_target fields
in your google_ads_config.rb file:
Google::Ads::GoogleAds::Config.new do |c|
# Valid levels: 'DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL'
c.log_level = 'INFO'
# Output destination, such as STDOUT, STDERR, or a file path
c.log_target = STDOUT
end
Custom logger
You can also specify your own custom Ruby Logger instance using the logger
field. If you specify logger, then log_level and log_target are ignored:
require 'logger'
# In google_ads_config.rb:
Google::Ads::GoogleAds::Config.new do |c|
c.logger = Logger.new('log/google_ads.log')
end
You can also assign a custom logger after instantiating the client using
client.logger=. Note that this only takes effect on service clients fetched
(client.service.<name>) after client.logger is set:
require 'logger'
client = Google::Ads::GoogleAds::GoogleAdsClient.new
client.logger = Logger.new(STDOUT)