Created
January 25, 2013 17:17
-
-
Save smostovoy/4636227 to your computer and use it in GitHub Desktop.
Rack/Grape MongodbLogger middleware for rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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