Module: Facebooker::Logging

Defined in:
lib/facebooker/logging.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.skip_api_loggingObject

Returns the value of attribute skip_api_logging.



13
14
15
# File 'lib/facebooker/logging.rb', line 13

def skip_api_logging
  @skip_api_logging
end

Class Method Details

.format_fb_params(params) ⇒ Object



33
34
35
# File 'lib/facebooker/logging.rb', line 33

def self.format_fb_params(params)
  params.map { |key,value| "#{key} = #{value}" }.join(', ')
end

.log_fb_api(method, params) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/facebooker/logging.rb', line 15

def self.log_fb_api(method, params)
  message = method # might customize later
  dump = format_fb_params(params)
  if block_given?
    result = nil
    seconds = Benchmark.realtime { result = yield }
    log_info(message, dump, seconds) unless skip_api_logging
    result
  else
    log_info(message, dump) unless skip_api_logging
    nil
  end
rescue Exception => e
  exception = "#{e.class.name}: #{e.message}: #{dump}"
  log_info(message, exception)
  raise
end

.log_info(message, dump, seconds = 0) ⇒ Object



37
38
39
40
41
# File 'lib/facebooker/logging.rb', line 37

def self.log_info(message, dump, seconds = 0)
  return unless Facebooker.logger
  log_message = "#{message} (#{seconds}) #{dump}"
  Facebooker.logger.info(log_message)
end