Skip to content

Instantly share code, notes, and snippets.

@guillermo
Created October 19, 2010 16:22
Show Gist options
  • Save guillermo/634494 to your computer and use it in GitHub Desktop.
Save guillermo/634494 to your computer and use it in GitHub Desktop.
application controller arround filter to log
around_filter do |controller, action|
@start_time = Time.now
set_trace_func proc { |event, file, line, id, binding, classname|
if (@file != file && @line != line)
@file, @line = file, line
if (%w(call c-call).include? event)
file = @file[(Rails.root.to_s.size+1)..-1]
if @file[0...(Rails.root.to_s.size)] == Rails.root.to_s && !(file =~ /vendor\/plugins\/newrelic_rpm/)
@logger ||= Logger.new(File.join(Rails.root,'tmp/trace'))
args = []
args << controller.controller_name.to_s
args << controller.action_name.to_s
args << @start_time.to_i
args << (Time.now - @start_time) * 1000.0
args << File.expand_path(file).sub(Rails.root.to_s,'').to_s+':'+line.to_s
args << classname.to_s
args << event.to_s
@logger.info(args.join(" , "))
end
end
end
}
action.call
set_trace_func nil
true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment