Class: Locomotive::Steam::Middlewares::Logging

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/locomotive/steam/middlewares/logging.rb

Overview

Track the request into the current logger

Instance Method Summary collapse

Methods included from Helpers

#decorate_entry, #default_liquid_context, #default_locale, #html?, #json?, #liquid_assigns, #live_editing?, #locale, #locales, #log, #make_local_path, #modify_path, #mounted_on, #page, #params, #path, #redirect_to, #render_response, #repositories, #request, #services, #site

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/locomotive/steam/middlewares/logging.rb', line 12

def call(env)
  now = Time.now

  log "Started #{env['REQUEST_METHOD'].upcase} \"#{env['PATH_INFO']}\" at #{now}".light_white, 0
  log "Params: #{env.fetch('steam.request').params.inspect}"

  app.call(env).tap do |response|
    done_in_ms = ((Time.now - now) * 10000).truncate / 10.0
    log "Completed #{code_to_human(response.first)} in #{done_in_ms}ms\n\n".green
  end
end