Module: Mongo::Logging

Included in:
Collection, Cursor, MongoClient
Defined in:
lib/mongo/util/logging.rb

Defined Under Namespace

Modules: Instrumenter

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.instrumenterObject



40
41
42
# File 'lib/mongo/util/logging.rb', line 40

def self.instrumenter
  @instrumenter || Instrumenter
end

.instrumenter=(instrumenter) ⇒ Object



44
45
46
# File 'lib/mongo/util/logging.rb', line 44

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

Instance Method Details

#instrument(name, payload = {}) ⇒ Object

Execute the block and log the operation described by name and payload.



30
31
32
33
34
35
36
37
38
# File 'lib/mongo/util/logging.rb', line 30

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) ⇒ Object

Log a message with the given level.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/mongo/util/logging.rb', line 11

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_messageObject



4
5
6
7
8
# File 'lib/mongo/util/logging.rb', line 4

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