Skip to content

Commit

Permalink
make Logging#instrument plugable
Browse files Browse the repository at this point in the history
  • Loading branch information
timoschilling committed Nov 14, 2012
1 parent 054b910 commit f5d709b
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/mongo/util/logging.rb
Expand Up @@ -29,12 +29,22 @@ def log(level, msg)
# Execute the block and log the operation described by name and payload.
def instrument(name, payload = {})
start_time = Time.now
res = yield
res = Logging.instrumenter.instrument(name, payload) do
yield
end
duration = Time.now - start_time
log_operation(name, payload, duration)
res
end

def self.instrumenter
@instrumenter || Instrumenter
end

def self.instrumenter=(instrumenter)
@instrumenter = instrumenter
end

protected

def log_operation(name, payload, duration)
Expand All @@ -50,5 +60,10 @@ def log_operation(name, payload, duration)
end
end

module Instrumenter
def self.instrument(name, payload = {})
yield
end
end
end
end

0 comments on commit f5d709b

Please sign in to comment.