class SPSPubLog

Constants

DEBUG
ERROR
FATAL
INFO
UNKNOWN
WARN

Attributes

level[RW]

Public Class Methods

new(host: 'sps', address: host, port: '59000', topic: 'log', charlimit: 280, level: Severity::DEBUG, subtopic: '') click to toggle source
# File lib/spspub_log.rb, line 37
def initialize(host: 'sps', address: host, port: '59000', topic: 'log', 
               charlimit: 280, level: Severity::DEBUG, subtopic: '')
      
  @sps = SPSPub.new(host: host, address: host, port: port)
  
  @level = set_level level
  
  @topic, @charlimit, @subtopic = topic, charlimit, subtopic
  sleep 0.05
end

Public Instance Methods

debug(raw_msg) click to toggle source
# File lib/spspub_log.rb, line 48
def debug(raw_msg)
  return if @level > Severity::DEBUG  
  pub_msg raw_msg
end
error(raw_msg) click to toggle source
# File lib/spspub_log.rb, line 53
def error(raw_msg)
  return if @level > Severity::ERROR  
  pub_msg raw_msg, :error
end
fatal(raw_msg) click to toggle source
# File lib/spspub_log.rb, line 58
def fatal(raw_msg)
  return if @level > Severity::FATAL  
  pub_msg raw_msg, :fatal
end
info(raw_msg) click to toggle source
# File lib/spspub_log.rb, line 63
def info(raw_msg)
  return if @level > Severity::INFO  
  pub_msg raw_msg, :info
end
level=(val) click to toggle source
# File lib/spspub_log.rb, line 72
def level=(val)
  @level = set_level val
end
unknown(raw_msg) click to toggle source
# File lib/spspub_log.rb, line 76
def unknown(raw_msg)
  pub_msg raw_msg, :unknown
end

Private Instance Methods

pub_msg(s, label=:debug) click to toggle source
# File lib/spspub_log.rb, line 82
def pub_msg(s, label=:debug)
  
  fullmsg, topic = s.split(/ *: */,2).reverse
  msg = fullmsg.length <= @charlimit ? fullmsg : \
      fullmsg[0..@charlimit - 3] + '...'
  fqm = [@topic, label.to_s, topic || @subtopic].compact.join('/') + ': ' \
      + msg
  
  @sps.notice(fqm)
end
set_level(level) click to toggle source
# File lib/spspub_log.rb, line 93
def set_level(level)
  
  if level.is_a? Symbol then
    %i(debug info warn error fatal unknown).zip(0..5).to_h[level]
  else
    level
  end    
  
end