Skip to content

Commit

Permalink
Merge pull request #7 from marshall-lee/fix_unsubscribing
Browse files Browse the repository at this point in the history
Fix serious memory leak
  • Loading branch information
aserafin committed Jun 26, 2015
2 parents d130386 + 296705e commit 6f76458
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/grape_logging/middleware/request_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@ def before
start_time

@db_duration = 0
ActiveSupport::Notifications.subscribe('sql.active_record') do |*args|
@subscription = ActiveSupport::Notifications.subscribe('sql.active_record') do |*args|
event = ActiveSupport::Notifications::Event.new(*args)
@db_duration += event.duration
end if defined?(ActiveRecord)
end

def after
stop_time
logger.info parameters(request, response)
logger.info parameters
ActiveSupport::Notifications.unsubscribe(@subscription) if @subscription
nil
end

protected
def parameters(request, response)
def parameters
{
path: request.path,
params: request.params.to_hash,
Expand Down

0 comments on commit 6f76458

Please sign in to comment.