module GroceryDelivery::Log

Logging wrapper rubocop:disable ClassVars

Public Class Methods

debug(msg) click to toggle source
# File lib/grocery_delivery/logging.rb, line 53
def self.debug(msg)
  if @@level == Logger::DEBUG
    msg.to_s.prepend('DEBUG: ')
    logit(Syslog::LOG_DEBUG, msg)
  end
end
error(msg) click to toggle source
# File lib/grocery_delivery/logging.rb, line 72
def self.error(msg)
  msg.to_s.prepend('ERROR: ')
  logit(Syslog::LOG_ERR, msg)
end
info(msg) click to toggle source
# File lib/grocery_delivery/logging.rb, line 60
def self.info(msg)
  if @@level == Logger::INFO
    msg.to_s.prepend('INFO: ')
    logit(Syslog::LOG_INFO, msg)
  end
end
init() click to toggle source
# File lib/grocery_delivery/logging.rb, line 27
def self.init
  Syslog.open(File.basename($PROGRAM_NAME, '.rb'))
  @@init = true
end
level() click to toggle source
# File lib/grocery_delivery/logging.rb, line 32
def self.level
  @@level
end
logit(level, msg) click to toggle source
# File lib/grocery_delivery/logging.rb, line 44
def self.logit(level, msg)
  init unless @@init
  # You can't do `Syslog.log(level, msg)` because if there is a
  # `%` in `msg` then ruby will interpret it as a printf string and
  # expect more arguments to log().
  Syslog.log(level, '%s', msg)
  puts msg if $stdout.tty? || @@stdout
end
stdout=(val) click to toggle source
# File lib/grocery_delivery/logging.rb, line 40
def self.stdout=(val)
  @@stdout = val
end
verbosity=(val) click to toggle source
# File lib/grocery_delivery/logging.rb, line 36
def self.verbosity=(val)
  @@level = val
end
warn(msg) click to toggle source
# File lib/grocery_delivery/logging.rb, line 67
def self.warn(msg)
  msg.to_s.prepend('WARN: ')
  logit(Syslog::LOG_WARNING, msg)
end