Class: QuietCommonLogger

Inherits:
Rack::CommonLogger
  • Object
show all
Includes:
Rack
Defined in:
lib/volt/server/rack/quiet_common_logger.rb

Constant Summary collapse

@@ignore_extensions =
%w(png jpg jpeg ico gif woff tff svg eot css js)

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/volt/server/rack/quiet_common_logger.rb', line 7

def call(env)
  path = env['PATH_INFO']
  began_at = Time.now
  status, header, body = @app.call(env)
  header = Utils::HeaderHash.new(header)
  base = ::File.basename(path)
  if base.index('.')
    ext = base.split('.').last
  else
    ext = nil
  end

  body = BodyProxy.new(body) do
    # Don't log on ignored extensions
    unless @@ignore_extensions.include?(ext)
      log(env, status, header, began_at)
    end
  end

  # Because of web sockets, the initial request doesn't finish, so we
  # can just trigger it now.
  unless ext || path.start_with?('/channel')
    log(env, status, header, began_at)
  end

  [status, header, body]
end