Module: ActiveCypher::Logging

Included in:
Base, Model::ConnectionOwner, Relationship
Defined in:
lib/active_cypher/logging.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.backendObject

The one true logger object



10
11
12
# File 'lib/active_cypher/logging.rb', line 10

def backend
  @backend
end

Class Method Details

.loggerObject

Public accessor used by the mix‑in



13
14
15
16
17
18
19
20
# File 'lib/active_cypher/logging.rb', line 13

def logger
  self.backend ||= begin
    base = Logger.new($stdout)
    base.level = ENV.fetch('AC_LOG_LEVEL', 'info').upcase
                    .then { |lvl| Logger.const_get(lvl) }
    ActiveSupport::TaggedLogging.new(base).tap { |l| l.tagged! 'ActiveCypher' }
  end
end

Instance Method Details

#log_bench(label) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/active_cypher/logging.rb', line 32

def log_bench(label)
  start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  yield
ensure
  ms = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - start) * 1_000).round(2)
  logger.debug { "#{label} (#{ms} ms)" }
end

#log_debug(msg) ⇒ Object



27
# File 'lib/active_cypher/logging.rb', line 27

def log_debug(msg) = logger.debug { msg }

#log_error(msg) ⇒ Object



30
# File 'lib/active_cypher/logging.rb', line 30

def log_error(msg) = logger.error { msg }

#log_info(msg) ⇒ Object



28
# File 'lib/active_cypher/logging.rb', line 28

def log_info(msg)  = logger.info  { msg }

#log_warn(msg) ⇒ Object



29
# File 'lib/active_cypher/logging.rb', line 29

def log_warn(msg)  = logger.warn  { msg }

#loggerObject


Instance helpers



26
# File 'lib/active_cypher/logging.rb', line 26

def logger         = Logging.logger