Module: RestClient

Defined in:
lib/couchrest/middlewares/logger.rb

Overview

inject our logger into key RestClient methods

Class Method Summary collapse

Class Method Details

.delete(uri, headers = nil) ⇒ Object



89
90
91
92
93
94
95
96
97
# File 'lib/couchrest/middlewares/logger.rb', line 89

def self.delete(uri, headers=nil)
  start_query = Time.now
  log = {:method => :delete, :uri => uri, :headers => headers}
  response = super(uri, headers=nil)
  end_query = Time.now
  log[:duration] = (end_query - start_query)
  CouchRest::Logger.record(log)
  response
end

.get(uri, headers = nil) ⇒ Object



59
60
61
62
63
64
65
66
67
# File 'lib/couchrest/middlewares/logger.rb', line 59

def self.get(uri, headers=nil)
  start_query = Time.now
  log = {:method => :get, :uri => uri, :headers => headers}
  response = super(uri, headers=nil)
  end_query = Time.now
  log[:duration] = (end_query - start_query)
  CouchRest::Logger.record(log)
  response
end

.post(uri, payload, headers = nil) ⇒ Object



69
70
71
72
73
74
75
76
77
# File 'lib/couchrest/middlewares/logger.rb', line 69

def self.post(uri, payload, headers=nil)
  start_query = Time.now
  log = {:method => :post, :uri => uri, :payload =>  (payload ? (JSON.load(payload) rescue 'parsing error') : nil), :headers => headers}
  response = super(uri, payload, headers=nil)
  end_query = Time.now
  log[:duration] = (end_query - start_query)
  CouchRest::Logger.record(log)
  response
end

.put(uri, payload, headers = nil) ⇒ Object



79
80
81
82
83
84
85
86
87
# File 'lib/couchrest/middlewares/logger.rb', line 79

def self.put(uri, payload, headers=nil)
  start_query = Time.now
  log = {:method => :put, :uri => uri, :payload => (payload ? (JSON.load(payload) rescue 'parsing error') : nil), :headers => headers}
  response = super(uri, payload, headers=nil)
  end_query = Time.now
  log[:duration] = (end_query - start_query)
  CouchRest::Logger.record(log)
  response
end