Created
January 22, 2013 17:04
-
-
Save tbuehlmann/4596310 to your computer and use it in GitHub Desktop.
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
# app/controllers/sessions_controller.rb | |
class SessionsController < ApplicationController | |
# ... | |
def create | |
user = User.authenticate(params[:username], params[:password]) | |
if user | |
session[:user_id] = user.id | |
ActiveSupport::Notifications.instrument('user.logged_in', :username => user.name) | |
redirect_to root_url, :notice => '...' | |
else | |
redirect_to login_url, :alert => '...' | |
end | |
end | |
end |
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
# config/initializers/user_transaction_logger.rb | |
class FormattedLogger < Logger | |
def format_message(severity, timestamp, progname, msg) | |
"#{timestamp.strftime('%d.%m.%Y %H:%M:%S')} #{msg}\n" | |
end | |
end | |
UserTransactionLogger = ActiveSupport::TaggedLogging.new(FormattedLogger.new(File.join(Rails.root, 'log', 'user_transaction.log'))) | |
ActiveSupport::Notifications.subscribe('user.logged_in') do |name, start, finish, id, payload| | |
UserTransactionLogger.tagged(payload[:username], 'User') do | |
UserTransactionLogger.info 'logged in' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment