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) |

> [!CAUTION]
> **Caution:** At the `DEBUG` level, logs contain complete request and response payloads, which may include sensitive account data and generate large log volumes. Use `DEBUG` only for local troubleshooting, and don't leave `DEBUG` logging enabled in production environments.

## Configuration

You can configure logging in your [`google_ads_config.rb`](https://github.com/googleads/google-ads-ruby/blob/HEAD/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)