Module: EventMachine::Protocols::Syslog

Defined in:
lib/em/syslog.rb

Constant Summary collapse

SEVERITIES =
{
  :emergency => 0,      # system is unusable
  :alert => 1,          # action must be taken immediately
  :critical => 2,       # critical conditions
  :error => 3,          # error conditions
  :warning => 4,        # warning conditions
  :notice => 5,         # normal but significant condition
  :informational => 6,  # informational messages
  :info => 6,           # informational messages (short name for the previous)
  :debug => 7           # debug-level messages
}

Class Method Summary collapse

Class Method Details

.log(severity, message, time = nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/em/syslog.rb', line 23

def log(severity, message, time = nil)
  raise "Syslog Server not set" if EM.syslog_server.nil?
  
  severity = SEVERITIES[severity] if severity.is_a? Symbol
  time ||= Time.now
  hostname = Socket.gethostname
  day = time.strftime('%b %d').sub(/0(\d)/, ' \\1')
  tag = "#{$0.split('/').last}[#{Process.pid}]"
  
  send_msg "<#{0 * 8 + severity}>#{day} #{time.strftime('%T')} #{hostname} #{tag}: #{message}"
end

.send_msg(data) ⇒ Object



35
36
37
38
39
# File 'lib/em/syslog.rb', line 35

def send_msg(data)
  EM.next_tick{
    EM.syslog_sd.send_datagram(data, EM.syslog_server, EM.syslog_port) 
  }
end