Module: LogicalModel::SafeLog::ClassMethods

Defined in:
lib/logical_model/safe_log.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#log_pathObject

Returns the value of attribute log_path.



23
24
25
# File 'lib/logical_model/safe_log.rb', line 23

def log_path
  @log_path
end

Instance Method Details

#log_failed(response) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/logical_model/safe_log.rb', line 34

def log_failed(response)
  begin
    error_message = ActiveSupport::JSON.decode(response.body)["message"]
  rescue => e
    error_message = "error"
  end
  msg = "LogicalModel Log: #{response.code} #{mask_api_key(response.effective_url)} in #{response.time}s FAILED: #{error_message}"
  self.logger.warn(msg)
  self.logger.debug("LogicalModel Log RESPONSE: #{response.body}")
end

#log_ok(response) ⇒ Object



29
30
31
32
# File 'lib/logical_model/safe_log.rb', line 29

def log_ok(response)
  self.logger.info("LogicalModel Log: #{response.code} #{mask_api_key(response.effective_url)} in #{response.time}s")
  self.logger.debug("LogicalModel Log RESPONSE: #{response.body}")
end

#loggerObject



45
46
47
# File 'lib/logical_model/safe_log.rb', line 45

def logger
  Logger.new(self.log_path || "log/logical_model.log")
end

#mask_api_key(str) ⇒ String

Filters api_key

Returns:

  • (String)


51
52
53
54
55
56
# File 'lib/logical_model/safe_log.rb', line 51

def mask_api_key(str)
  if use_api_key && str
    str = str.gsub(api_key,'[SECRET]')
  end
  str
end