Skip to content

Commit

Permalink
l2met log formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
rwdaigle committed Oct 5, 2012
1 parent c896e2a commit 0eef180
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions app/controllers/sessions_controller.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ def create
user = User.authenticate(request.env['omniauth.auth']) user = User.authenticate(request.env['omniauth.auth'])
log_in_user(user.id) log_in_user(user.id)
redirect_to search_gists_path redirect_to search_gists_path
log({ns: self, fn: __method__, measure: true, at: 'login'}, user)
end end
end end
7 changes: 4 additions & 3 deletions app/models/gist.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -35,19 +35,20 @@ def import(gh_gist)
} }


if(existing_gist = where(gh_id: gh_id).first) if(existing_gist = where(gh_id: gh_id).first)
log({ns: self, fn: __method__}, user, existing_gist) log({ns: self, fn: __method__, measure: true, at: 'gist-imported'}, user, existing_gist)
existing_gist.update_attributes(attributes) existing_gist.update_attributes(attributes)
existing_gist existing_gist
else else
new_gist = create(attributes) new_gist = create(attributes)
log({ns: self, fn: __method__}, user, new_gist) log({ns: self, fn: __method__, measure: true, at: 'gist-created'}, user, new_gist)
new_gist new_gist
end end
end end


def search(user, q) def search(user, q)
q = q.blank? ? '*' : q q = q.blank? ? '*' : q
log({ns: self, fn: __method__, query: q}, user) do log({ns: self, fn: __method__, query: q, measure: true, at: 'search'}, user)
log({ns: self, fn: __method__, query: q, measure: true}, user) do
tire.search do tire.search do
query { string q } query { string q }
sort { by :gh_created_at, 'desc' } sort { by :gh_created_at, 'desc' }
Expand Down
4 changes: 2 additions & 2 deletions app/models/gist_fetcher.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def fetch_user(user_id)


# Make sure have all gist stubs imported # Make sure have all gist stubs imported
def fetch_gists(gh, user) def fetch_gists(gh, user)
log({ns: self, fn: __method__}, user) do log({ns: self, fn: __method__, measure: true}, user) do
gh.gists.each do |gh_gist| gh.gists.each do |gh_gist|
Gist.import(gh_gist) Gist.import(gh_gist)
end end
Expand All @@ -36,7 +36,7 @@ def fetch_gists(gh, user)


# Fetch individual gists from API to get file contents # Fetch individual gists from API to get file contents
def fetch_files(gh, user) def fetch_files(gh, user)
log({ns: self, fn: __method__}, user) do log({ns: self, fn: __method__, measure: true}, user) do
user.gists.pluck(:gh_id).each do |gh_gist_id| user.gists.pluck(:gh_id).each do |gh_gist_id|
GistFile.import(gh.gist(gh_gist_id)) GistFile.import(gh.gist(gh_gist_id))
end end
Expand Down
4 changes: 2 additions & 2 deletions app/models/user.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ def authenticate(auth)
} }


if(existing_user = User.where(gh_id: auth.uid).first) if(existing_user = User.where(gh_id: auth.uid).first)
log({ns: self, fn: __method__}, existing_user) log({ns: self, fn: __method__, measure: true, at: 'user-authenticated'}, existing_user)
existing_user.update_attributes(attributes) existing_user.update_attributes(attributes)
existing_user existing_user
else else
new_user = User.create(attributes) new_user = User.create(attributes)
log({ns: self, fn: __method__}, new_user) log({ns: self, fn: __method__, measure: true, at: 'user-created'}, new_user)
new_user new_user
end end
end end
Expand Down
4 changes: 4 additions & 0 deletions config/initializers/logging.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def log_data_from(*segments)
end end


end end

def log(*segments, &block)
self.class.log(*segments, &block)
end
end end


class Hash class Hash
Expand Down

0 comments on commit 0eef180

Please sign in to comment.