module Hoss::Logging

@api private

Constants

LEVELS
PREFIX

Public Instance Methods

debug(msg, *args, &block) click to toggle source
# File lib/hoss/logging.rb, line 33
def debug(msg, *args, &block)
  log(:debug, msg, *args, &block)
end
error(msg, *args, &block) click to toggle source
# File lib/hoss/logging.rb, line 45
def error(msg, *args, &block)
  log(:error, msg, *args, &block)
end
fatal(msg, *args, &block) click to toggle source
# File lib/hoss/logging.rb, line 49
def fatal(msg, *args, &block)
  log(:fatal, msg, *args, &block)
end
info(msg, *args, &block) click to toggle source
# File lib/hoss/logging.rb, line 37
def info(msg, *args, &block)
  log(:info, msg, *args, &block)
end
warn(msg, *args, &block) click to toggle source
# File lib/hoss/logging.rb, line 41
def warn(msg, *args, &block)
  log(:warn, msg, *args, &block)
end

Private Instance Methods

log(lvl, msg, *args) click to toggle source
# File lib/hoss/logging.rb, line 55
def log(lvl, msg, *args)
  return unless (logger = @config&.logger)
  return unless LEVELS[lvl] >= (@config&.log_level || 0)

  formatted_msg = prepend_prefix(format(msg.to_s, *args))

  return logger.send(lvl, formatted_msg) unless block_given?

  logger.send(lvl, "#{formatted_msg}\n#{yield}")
end
prepend_prefix(str) click to toggle source
# File lib/hoss/logging.rb, line 66
def prepend_prefix(str)
  "#{PREFIX}#{str}"
end