Skip to content

Instantly share code, notes, and snippets.

@smostovoy
Created January 25, 2013 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smostovoy/4636227 to your computer and use it in GitHub Desktop.
Save smostovoy/4636227 to your computer and use it in GitHub Desktop.
Rack/Grape MongodbLogger middleware for rails
class MongodbLogger::Rack
def initialize(app)
@app = app
end
def call(env)
log_attrs = {:method => env['REQUEST_METHOD'],
:action => env['PATH_INFO'],
:controller => 'API',
:path => env['PATH_INFO'],
:url => env['SERVER_NAME'] + env['PATH_INFO'],
:params => env['rack.input'].read,
:ip => env['REMOTE_ADDR'] }
Rails.logger.mongoize(log_attrs) do
return @app.call(env)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment