Class: Smartkiosk::Client::Logging::Middleware
- Inherits:
-
Object
- Object
- Smartkiosk::Client::Logging::Middleware
- Defined in:
- lib/smartkiosk/client/logging.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
- #extract_content_length(headers) ⇒ Object
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
- #log(env, status, header, began_at) ⇒ Object
Constructor Details
#initialize(app) ⇒ Middleware
Returns a new instance of Middleware.
9 10 11 |
# File 'lib/smartkiosk/client/logging.rb', line 9 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/smartkiosk/client/logging.rb', line 13 def call(env) began_at = Time.now env['rack.logger'] = Smartkiosk::Client::Logging.logger status, header, body = @app.call(env) header = Rack::Utils::HeaderHash.new(header) log(env, status, header, began_at) [status, header, body] end |
#extract_content_length(headers) ⇒ Object
33 34 35 36 |
# File 'lib/smartkiosk/client/logging.rb', line 33 def extract_content_length(headers) value = headers['Content-Length'] or return '-' value.to_s == '0' ? '-' : value end |
#log(env, status, header, began_at) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/smartkiosk/client/logging.rb', line 23 def log(env, status, header, began_at) now = Time.now length = extract_content_length(header) Smartkiosk::Client::Logging.logger.info "#{status.to_s[0..3]} #{env["REQUEST_METHOD"]} " << "#{env["PATH_INFO"]}#{env["QUERY_STRING"].empty? ? "" : "?"+env["QUERY_STRING"]}, " << "#{length} (#{now - began_at})" end |