module GoogleLogger
Main module which should serve as an interface to all functionalities
Constants
- VERSION
Attributes
Public Class Methods
Returns GoogleLogger
configuration
@return [GoogleLogger::Configuration] current GoogleLogger
configuration
# File lib/google_logger.rb, line 24 def configuration @configuration ||= Configuration.new end
Yields the cofiguration class
@yield [GoogleLogger::Configuration] current GoogleLogger
configuration
@return [GoogleLogger::Configuration] GoogleLogger
configuration with assigned values
# File lib/google_logger.rb, line 33 def configure yield(configuration) if block_given? configuration.validate! configuration end
Creates a new entry
@param [String, Hash] payload content of the log @param [String] log_name log_name which can be used to filter logs @param [Symbol] severity severity of the log
return [Boolean] `true` if the entry was successfully written
# File lib/google_logger.rb, line 48 def create_entry(payload, log_name: 'default_log', severity: :DEFAULT) logger_instance = logger entry = logger_instance.build_entry(payload, log_name: log_name, severity: severity) logger_instance.write_entry(entry) end
# File lib/google_logger.rb, line 110 def deep_replace_secret_params(params) ParamsReplacer.deep_replace_secret_params(params) end
Creates a new entry for an exception which includes exception message, class and backtrace
@param [StandardError] exception exception to be logged
return [Boolean] `true` if the entry was successfully written
# File lib/google_logger.rb, line 59 def log_exception(exception) payload = { message: exception.message, exception: exception.class.name, bactrace: exception.backtrace&.first(configuration.backtrace_length) } create_entry(payload, log_name: 'error', severity: :ERROR) rescue StandardError => e log_google_logger_error(e) end
Log gem errors locally if local_logger is present
@param [StandardError] exception the error that will be logged
# File lib/google_logger.rb, line 105 def log_google_logger_error(exception) local_logger = GoogleLogger.configuration.local_logger local_logger.error "GOOGLE_LOGGER ERROR: #{exception.inspect}" if local_logger.present? end
Creates a new entry for a controller request, the entry includes params, request URL, client ip address and http method
@param [ActionDispatch::Request] request request to be logged @param [ActionController::StrongParameters] params parameters to be logged
return [Boolean] `true` if the entry was successfully written
# File lib/google_logger.rb, line 78 def log_request(request, params) payload = { params: params, original_url: request.original_url, ip: request.ip, method: request.method } create_entry(payload, log_name: 'request', severity: :INFO) rescue StandardError => e log_google_logger_error(e) end
Returns the currently used logger
@return [Object] GoogleLogger::Logger by default, local logger if `loc_locally` is set to true
# File lib/google_logger.rb, line 94 def logger if configuration.log_locally Loggers::LocalLogger.new else Loggers::CloudLogger.new end end