Initial logging support

This commit is contained in:
Steven Bazyl 2012-12-30 11:26:18 -08:00
parent 85593ba938
commit 8f453134d7
2 changed files with 42 additions and 6 deletions

View File

@ -19,6 +19,7 @@ require 'multi_json'
require 'compat/multi_json' require 'compat/multi_json'
require 'stringio' require 'stringio'
require 'google/api_client/logging'
require 'google/api_client/version' require 'google/api_client/version'
require 'google/api_client/errors' require 'google/api_client/errors'
require 'google/api_client/environment' require 'google/api_client/environment'
@ -29,11 +30,15 @@ require 'google/api_client/result'
require 'google/api_client/media' require 'google/api_client/media'
require 'google/api_client/service_account' require 'google/api_client/service_account'
require 'google/api_client/batch' require 'google/api_client/batch'
require 'google/api_client/railtie' if defined?(Rails)
module Google module Google
## ##
# This class manages APIs communication. # This class manages APIs communication.
class APIClient class APIClient
include Google::Logging
## ##
# Creates a new Google API client. # Creates a new Google API client.
# #
@ -74,12 +79,13 @@ module Google
# Most developers will want to leave this value alone and use the # Most developers will want to leave this value alone and use the
# application_name option. # application_name option.
application_string = ( if options[:application_name]
options[:application_name] ? ( app_name = options[:application_name]
"#{options[:application_name]}/" + app_version = options[:application_version]
"#{options[:application_version] || '0.0.0'}" application_string = "#{app_name}/#{app_version || '0.0.0'}"
) : "" else
) logger.warn("Please provide :application_name and :application_version when initializing the APIClient")
end
self.user_agent = options[:user_agent] || ( self.user_agent = options[:user_agent] || (
"#{application_string} " + "#{application_string} " +
"google-api-ruby-client/#{VERSION::STRING} " + "google-api-ruby-client/#{VERSION::STRING} " +

View File

@ -0,0 +1,30 @@
require 'logger'
module Google
class APIClient
class << self
##
# Logger for the API client
#
# @return [Logger] logger instance.
attr_accessor :logger
end
self.logger = Logger.new(STDOUT)
self.logger.level = Logger::WARN
end
##
# Module to make accessing the logger simpler
module Logging
##
# Logger for the API client
#
# @return [Logger] logger instance.
def logger
Google::APIClient.logger
end
end
end