lib/deas/logging.rb in deas-0.17.1 vs lib/deas/logging.rb in deas-0.18.0
- old
+ new
@@ -55,11 +55,12 @@
class VerboseLogging < BaseLogging
RESPONSE_STATUS_NAMES = {
200 => 'OK',
- 400 => 'BAD REQUEST' ,
+ 302 => 'FOUND',
+ 400 => 'BAD REQUEST',
401 => 'UNAUTHORIZED',
403 => 'FORBIDDEN',
404 => 'NOT FOUND',
408 => 'TIMEOUT',
500 => 'ERROR'
@@ -73,10 +74,11 @@
log " Method: #{request.request_method.inspect}"
log " Path: #{request.path.inspect}"
end
env['deas.logging'] = Proc.new{ |msg| log(msg) }
status, headers, body = super(env)
+ log " Redir: #{headers['Location']}" if headers.key?('Location')
log "===== Completed in #{env['deas.time_taken']}ms (#{response_display(status)}) ====="
[ status, headers, body ]
end
def response_display(status)
@@ -91,28 +93,34 @@
# common logging behavior.
def call!(env)
env['deas.logging'] = Proc.new{ |msg| } # no-op
status, headers, body = super(env)
request = Rack::Request.new(env)
- log SummaryLine.new({
+ line_attrs = {
'method' => request.request_method,
'path' => request.path,
'handler' => env['deas.handler_class_name'],
'params' => env['sinatra.params'],
'time' => env['deas.time_taken'],
'status' => status
- })
+ }
+ if headers.key?('Location')
+ line_attrs['redir'] = headers['Location']
+ end
+ log SummaryLine.new(line_attrs)
[ status, headers, body ]
end
end
module SummaryLine
def self.keys
- %w{time status method path handler params}
+ %w{time status method path handler params redir}
end
def self.new(line_attrs)
- self.keys.map{ |k| "#{k}=#{line_attrs[k].inspect}" }.join(' ')
+ self.keys.select{ |k| line_attrs.key?(k) }.
+ map{ |k| "#{k}=#{line_attrs[k].inspect}" }.
+ join(' ')
end
end
module RoundedTime
ROUND_PRECISION = 2