Permalink
Browse files

Add user-context to logged events

  • Loading branch information...
1 parent 7ae5acf commit 76083c2c81c05e78117660e2aebcf5fcd4a64568 @rwdaigle committed May 24, 2012
Showing with 21 additions and 8 deletions.
  1. +4 −2 app/loaders/inbound_email_loader.rb
  2. +6 −4 app/loaders/wordnik_wod_loader.rb
  3. +11 −2 lib/event_logging.rb
View
6 app/loaders/inbound_email_loader.rb
@@ -3,8 +3,10 @@ class InboundEmailLoader
class << self
def load!(from, text)
- log({action: "email-import", from: from, text: text}) do
- Subject.add_vocabulary_word(text)
+ log_context({user: 'ryan', user_id: 1}) do
+ log({action: "email-import", from: from, text: text}) do
+ Subject.add_vocabulary_word(text)
+ end
end
end
end
View
10 app/loaders/wordnik_wod_loader.rb
@@ -5,10 +5,12 @@ class WordnikWODLoader
class << self
def load!(from = Date.today)
- today = Date.today
- while(from <= today)
- load_wod(from)
- from = from + 1.day
+ log_context({user: 'ryan', user_id: 1}) do
+ today = Date.today
+ while(from <= today)
+ load_wod(from)
+ from = from + 1.day
+ end
end
end
View
13 lib/event_logging.rb
@@ -6,11 +6,20 @@ module EventLogger
module ClassMethods
+ def log_context(*segments, &block)
+ Scrolls.context(log_data_from(*segments), &block)
+ end
+
def log(*segments, &block)
- call_log_data = segments.inject({}) do |map, segment|
+ Scrolls.log(log_data_from(*segments), &block)
+ end
+
+ private
+
+ def log_data_from(*segments)
+ segments.inject({}) do |map, segment|
map.merge!(segment.to_log)
end
- Scrolls.log(call_log_data, &block)
end
end

0 comments on commit 76083c2

Please sign in to comment.