Permalink
Browse files

Merge pull request #131 from timoschilling/plugable_logger_instrument

plugable logger instrument
  • Loading branch information...
2 parents 054b910 + f5d709b commit 881ff7fbeff1c38f003a8099dd4a9a429ed37ec7 @TylerBrock TylerBrock committed Nov 14, 2012
Showing with 16 additions and 1 deletion.
  1. +16 −1 lib/mongo/util/logging.rb
View
@@ -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)
@@ -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 881ff7f

Please sign in to comment.