Module: Facebooker::Logging

Defined in:
lib/facebooker/logging.rb

Class Method Summary collapse

Class Method Details

.format_fb_params(params) ⇒ Object



40
41
42
# File 'lib/facebooker/logging.rb', line 40

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

.log_fb_api(method, params) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/facebooker/logging.rb', line 22

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



44
45
46
47
48
# File 'lib/facebooker/logging.rb', line 44

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

.skip_api_loggingObject



17
18
19
# File 'lib/facebooker/logging.rb', line 17

def self.skip_api_logging
  @skip_api_logging
end

.skip_api_logging=(val) ⇒ Object



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

def self.skip_api_logging=(val)
  @skip_api_logging=val
end