Change up logging a little bit

This commit is contained in:
Raphael Sofaer 2011-02-10 11:52:00 -08:00
parent 7a6d1d3378
commit f1fe913527
3 changed files with 27 additions and 19 deletions

View file

@ -33,10 +33,10 @@ class ApplicationController < ActionController::Base
end
def which_action_and_user
str = "controller=#{self.class} action=#{self.action_name} "
str = "event=request_with_user controller=#{self.class} action=#{self.action_name} "
if current_user
str << "uid=#{current_user.id}"
str << "created_at=#{current_user.created_at.to_date.to_s}" if current_user.created_at
str << "uid=#{current_user.id} "
str << "user_created_at=#{current_user.created_at.to_date.to_s} " if current_user.created_at
else
str << 'uid=nil'
end

View file

@ -218,19 +218,26 @@ class User < ActiveRecord::Base
end
def accept_invitation!(opts = {})
if self.invited?
log_string = "event=invitation_accepted username=#{opts[:username]} "
log_string << "inviter=#{invitations_to_me.first.sender.diaspora_handle}" if invitations_to_me.first
Rails.logger.info log_string
self.setup(opts)
self.invitation_token = nil
self.password = opts[:password]
self.password_confirmation = opts[:password_confirmation]
self.save!
invitations_to_me.each{|invitation| invitation.to_request!}
log_string = "event=invitation_accepted username=#{opts[:username]} uid=#{self.id} "
log_string << "inviter=#{invitations_to_me.first.sender.diaspora_handle} " if invitations_to_me.first
begin
if self.invited?
self.setup(opts)
self.invitation_token = nil
self.password = opts[:password]
self.password_confirmation = opts[:password_confirmation]
self.save!
invitations_to_me.each{|invitation| invitation.to_request!}
log_string << "success"
Rails.logger.info log_string
self.reload # Because to_request adds a request and saves elsewhere
self
self.reload # Because to_request adds a request and saves elsewhere
self
end
rescue Exception => e
log_string << "failure"
Rails.logger.info log_string
raise e
end
end

View file

@ -7,13 +7,14 @@ describe StreamHelper do
@post = @user.post(:status_message, :message => "hi", :to => @aspect.id)
end
it 'renders a new comment form' do
new_comment_form(@post.id).should ==
@controller.render_to_string(:partial => 'comments/new_comment', :locals => {:post_id => @post.id})
new_comment_form(@post.id, @user).should ==
@controller.render_to_string(:partial => 'comments/new_comment',
:locals => {:post_id => @post.id, :current_user => @user})
end
it 'renders it fast the second time' do
new_comment_form(@post.id)
new_comment_form(@post.id, @user)
time = Benchmark.realtime{
new_comment_form(@post.id)
new_comment_form(@post.id, @user)
}
(time*1000).should < 1
end