module Mongo::Logging
Public Class Methods
instrumenter()
click to toggle source
# File lib/mongo/functional/logging.rb, line 62 def self.instrumenter @instrumenter end
instrumenter=(instrumenter)
click to toggle source
# File lib/mongo/functional/logging.rb, line 66 def self.instrumenter=(instrumenter) @instrumenter = instrumenter end
Public Instance Methods
instrument(name, payload = {}) { || ... }
click to toggle source
Execute the block and log the operation described by name and payload.
# File lib/mongo/functional/logging.rb, line 52 def instrument(name, payload = {}) start_time = Time.now res = Logging.instrumenter.instrument(name, payload) do yield end duration = Time.now - start_time log_operation(name, payload, duration) res end
log(level, msg)
click to toggle source
Log a message with the given level.
# File lib/mongo/functional/logging.rb, line 33 def log(level, msg) return unless @logger case level when :fatal then @logger.fatal "MONGODB [FATAL] #{msg}" when :error then @logger.error "MONGODB [ERROR] #{msg}" when :warn then @logger.warn "MONGODB [WARNING] #{msg}" when :info then @logger.info "MONGODB [INFO] #{msg}" when :debug then @logger.debug "MONGODB [DEBUG] #{msg}" else @logger.debug "MONGODB [DEBUG] #{msg}" end end
write_logging_startup_message()
click to toggle source
# File lib/mongo/functional/logging.rb, line 26 def write_logging_startup_message log(:debug, "Logging level is currently :debug which could negatively impact " + "client-side performance. You should set your logging level no lower than " + ":info in production.") end
Protected Instance Methods
log_operation(name, payload, duration)
click to toggle source
# File lib/mongo/functional/logging.rb, line 72 def log_operation(name, payload, duration) @logger && @logger.debug do msg = "MONGODB " msg << "(%.1fms) " % (duration * 1000) msg << "#{payload[:database]}['#{payload[:collection]}'].#{name}(" msg << payload.values_at(:selector, :document, :documents, :fields ).compact.map(&:inspect).join(', ') + ")" msg << ".skip(#{payload[:skip]})" if payload[:skip] msg << ".limit(#{payload[:limit]})" if payload[:limit] msg << ".sort(#{payload[:order]})" if payload[:order] msg end end