Last active
December 17, 2015 11:29
-
-
Save fonsecajavier/5602209 to your computer and use it in GitHub Desktop.
Track users for every action (useful for logging in production)
This file contains hidden or 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 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