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 'stringio'
require 'google/api_client/logging'
require 'google/api_client/version'
require 'google/api_client/errors'
require 'google/api_client/environment'
@ -29,11 +30,15 @@ require 'google/api_client/result'
require 'google/api_client/media'
require 'google/api_client/service_account'
require 'google/api_client/batch'
require 'google/api_client/railtie' if defined?(Rails)
module Google
##
# This class manages APIs communication.
class APIClient
include Google::Logging
##
# Creates a new Google API client.
#
@ -74,12 +79,13 @@ module Google
# Most developers will want to leave this value alone and use the
# application_name option.
application_string = (
options[:application_name] ? (
"#{options[:application_name]}/" +
"#{options[:application_version] || '0.0.0'}"
) : ""
)
if options[:application_name]
app_name = options[:application_name]
app_version = options[:application_version]
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] || (
"#{application_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