module Elected::Logging::ClassMethods

Public Instance Methods

debug(string) click to toggle source
# File lib/elected/logging.rb, line 24
def debug(string)
  log string, :debug
end
debug_var(var_name, var, meth = :inspect, level = :debug) click to toggle source
# File lib/elected/logging.rb, line 12
def debug_var(var_name, var, meth = :inspect, level = :debug)
  msg   = var.nil? ? 'NIL' : var.send(meth)
  msg   = msg[0..-2] if msg[-1, 1] == "\n"
  klass = var.is_a?(Class) ? var.name : var.class.name
  Elected.logger.send level, "#{log_prefix} #{var_name} : (#{klass}:#{var.object_id}) #{msg}"
end
error(string) click to toggle source
# File lib/elected/logging.rb, line 36
def error(string)
  log string, :error
end
info(string) click to toggle source
# File lib/elected/logging.rb, line 28
def info(string)
  log string, :info
end
log(string, type = :debug) click to toggle source
# File lib/elected/logging.rb, line 19
def log(string, type = :debug)
  msg = "#{log_prefix} #{string}"
  Elected.logger.send type, msg
end
log_prefix(length = 60) click to toggle source
# File lib/elected/logging.rb, line 40
def log_prefix(length = 60)
  prefix = name
  labels = log_prefix_labels
  prefix += ".#{labels.last}" if labels
  prefix = prefix.rjust(length, ' ')[-length, length]
  prefix += ' |'
  prefix
end
log_prefix_labels() click to toggle source
# File lib/elected/logging.rb, line 57
def log_prefix_labels
  caller.
    reject { |x| x.index(__FILE__) }.
    map { |x| x =~ /(.*):(.*):in `(.*)'/ ? [$1, $2, $3] : nil }.
    first
end
run_thread_count() click to toggle source
# File lib/elected/logging.rb, line 49
def run_thread_count
  Thread.list.select { |thread| thread.status == 'run' }.count
end
thread_count() click to toggle source
# File lib/elected/logging.rb, line 53
def thread_count
  Thread.list.count
end
warn(string) click to toggle source
# File lib/elected/logging.rb, line 32
def warn(string)
  log string, :warn
end