Module: Aerospike::Loggable

Included in:
Aerospike
Defined in:
lib/aerospike/loggable.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.debug(prefix, payload, runtime) ⇒ Object



18
19
20
# File 'lib/aerospike/loggable.rb', line 18

def self.debug(prefix, payload, runtime)
  Aerospike.logger.debug([ prefix, payload, "runtime: #{runtime}" ].join(' '))
end

.error(prefix, payload, runtime) ⇒ Object



30
31
32
# File 'lib/aerospike/loggable.rb', line 30

def self.error(prefix, payload, runtime)
  Aerospike.logger.error([ prefix, payload, "runtime: #{runtime}" ].join(' '))
end

.info(prefix, payload, runtime) ⇒ Object



26
27
28
# File 'lib/aerospike/loggable.rb', line 26

def self.info(prefix, payload, runtime)
  Aerospike.logger.info([ prefix, payload, "runtime: #{runtime}" ].join(' '))
end

.log_operations(prefix, ops, runtime) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/aerospike/loggable.rb', line 6

def self.log_operations(prefix, ops, runtime)
  indent  = " "*prefix.length
  if ops.length == 1
    Aerospike.logger.debug([ prefix, ops.first.log_inspect, "runtime: #{runtime}" ].join(' '))
  else
    first, *middle, last = ops
    Aerospike.logger.debug([ prefix, first.log_inspect ].join(' '))
    middle.each { |m| Aerospike.logger.debug([ indent, m.log_inspect ].join(' ')) }
    Aerospike.logger.debug([ indent, last.log_inspect, "runtime: #{runtime}" ].join(' '))
  end
end

.warn(prefix, payload, runtime) ⇒ Object



22
23
24
# File 'lib/aerospike/loggable.rb', line 22

def self.warn(prefix, payload, runtime)
  Aerospike.logger.warn([ prefix, payload, "runtime: #{runtime}" ].join(' '))
end

Instance Method Details

#default_loggerObject



43
44
45
46
47
# File 'lib/aerospike/loggable.rb', line 43

def default_logger
  logger = Logger.new(STDOUT)
  logger.level = Logger::FATAL
  logger
end

#loggerObject



34
35
36
37
# File 'lib/aerospike/loggable.rb', line 34

def logger
  return @logger if defined?(@logger)
  @logger = rails_logger || default_logger
end

#logger=(logger) ⇒ Object



49
50
51
# File 'lib/aerospike/loggable.rb', line 49

def logger=(logger)
  @logger = logger
end

#rails_loggerObject



39
40
41
# File 'lib/aerospike/loggable.rb', line 39

def rails_logger
  defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger
end