Skip to content

Instantly share code, notes, and snippets.

@fonsecajavier
Last active December 17, 2015 11:29
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 fonsecajavier/5602209 to your computer and use it in GitHub Desktop.
Save fonsecajavier/5602209 to your computer and use it in GitHub Desktop.
Track users for every action (useful for logging in production)
class ApplicationController < ActionController::Base
prepend_before_filter :log_user
def log_user
begin
if current_user
Rails.logger.info "#{controller_name}##{action_name} triggered by user id ##{current_user.id}, params: #{params.inspect}"
else
Rails.logger.info "#{controller_name}##{action_name} triggered by not-signed-in user, params: #{params.inspect}"
end
rescue => ex
Rails.logger.info "ApplicationController#log_user exception: #{ex.class} - #{ex.message}\n" + ex.backtrace.join("\n")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment