Class: Rack::HTTPLogger
- Inherits:
-
Object
- Object
- Rack::HTTPLogger
- Defined in:
- lib/rack/http-logger.rb
Constant Summary collapse
- VERSION =
'0.2.1'
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ HTTPLogger
constructor
A new instance of HTTPLogger.
Constructor Details
#initialize(app, options = {}) ⇒ HTTPLogger
Returns a new instance of HTTPLogger.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/rack/http-logger.rb', line 5 def initialize(app, = {}) @app = app @stream = [:stream] || $stdout @stream.sync = true unless .fetch(:sync, true) @source = [:source] || "rack-http-logger" @method = [:method] ? "#{[:method]}".upcase : "LOG" @path = [:path] || "/" end |
Instance Method Details
#call(env) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rack/http-logger.rb', line 16 def call(env) request = Rack::Request.new(env) return @app.call(env) unless request.request_method == @method and request.path == @path if request.media_type == "application/json" and (body = request.body.read).length.nonzero? log JSON.parse(body) else log request.params end [201, {"Content-Type" => "text/plain"}, []] end |