Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #131 from timoschilling/plugable_logger_instrument

plugable logger instrument
  • Loading branch information...
commit 881ff7fbeff1c38f003a8099dd4a9a429ed37ec7 2 parents 054b910 + f5d709b
Tyler Brock TylerBrock authored
Showing with 16 additions and 1 deletion.
  1. +16 −1 lib/mongo/util/logging.rb
17 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
Please sign in to comment.
Something went wrong with that request. Please try again.