Class: RestCore::CommonLogger
- Inherits:
-
Object
- Object
- RestCore::CommonLogger
show all
- Includes:
- Middleware
- Defined in:
- lib/rest-core/middleware/common_logger.rb
Constant Summary
Constants included
from Middleware
Middleware::UNRESERVED
Constants included
from RestCore
ASYNC, CLIENT, DRY, FAIL, HIJACK, LOG, PROMISE, REQUEST_HEADERS, REQUEST_METHOD, REQUEST_PATH, REQUEST_PAYLOAD, REQUEST_QUERY, REQUEST_URI, RESPONSE_BODY, RESPONSE_HEADERS, RESPONSE_KEY, RESPONSE_SOCKET, RESPONSE_STATUS, Simple, TIMER, Universal, VERSION
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Middleware
contain_binary?, #contain_binary?, escape, #escape, #fail, #id, included, #log, merge_hash, #merge_hash, #percent_encode, percent_encode, request_uri, #request_uri, #run, #string_keys, string_keys
Methods included from RestCore
eagerload, id
Class Method Details
.members ⇒ Object
6
|
# File 'lib/rest-core/middleware/common_logger.rb', line 6
def self.members; [:log_method]; end
|
Instance Method Details
#call(env) ⇒ Object
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/rest-core/middleware/common_logger.rb', line 9
def call env
start_time = Time.now
flushed = flush(env)
app.call(flushed){ |response|
yield(process(response, start_time))
}
rescue
process(flushed, start_time)
raise
end
|
#flush(env) ⇒ Object
24
25
26
27
28
29
|
# File 'lib/rest-core/middleware/common_logger.rb', line 24
def flush env
return env if !log_method(env) || env[DRY]
(env[LOG] || []).compact.
each{ |obj| log_method(env).call("RestCore: #{obj}") }
env.merge(LOG => [])
end
|
#log_request(start_time, response) ⇒ Object
31
32
33
34
|
# File 'lib/rest-core/middleware/common_logger.rb', line 31
def log_request start_time, response
Event::Requested.new(Time.now - start_time,
"#{response[RC::REQUEST_METHOD].to_s.upcase} #{request_uri(response)}")
end
|
#process(response, start_time) ⇒ Object
20
21
22
|
# File 'lib/rest-core/middleware/common_logger.rb', line 20
def process response, start_time
flush(log(response, log_request(start_time, response)))
end
|