Class: RestCore::CommonLogger
- Inherits:
-
Object
- Object
- RestCore::CommonLogger
- Includes:
- Middleware
- Defined in:
- lib/rest-core/middleware/common_logger.rb
Class Method Summary collapse
Instance Method Summary collapse
- #call(env) ⇒ Object
- #flush(env) ⇒ Object
- #log_request(start_time, response) ⇒ Object
- #process(response, start_time) ⇒ Object
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[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 |