Class: ActiveLogger::Formatters::Syslog

Inherits:
Base
  • Object
show all
Defined in:
lib/active_logger/formatters/syslog.rb

Overview

:nodoc:

Defined Under Namespace

Classes: LevelMap

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#clear_tags!, #current_tags, #default_progname, #pid, #pop_tags, #push_tags, #tagged, #tags_text

Constructor Details

#initialize(hostname: nil, facility: nil, maxsize: nil) ⇒ Syslog

Returns a new instance of Syslog.



27
28
29
30
31
# File 'lib/active_logger/formatters/syslog.rb', line 27

def initialize(hostname: nil, facility: nil, maxsize: nil)
  @hostname = hostname
  @facility = facility
  @maxsize = maxsize
end

Instance Attribute Details

#facilityObject

Returns the value of attribute facility.



9
10
11
# File 'lib/active_logger/formatters/syslog.rb', line 9

def facility
  @facility
end

#hostnameObject

Returns the value of attribute hostname.



9
10
11
# File 'lib/active_logger/formatters/syslog.rb', line 9

def hostname
  @hostname
end

#maxsizeObject

Returns the value of attribute maxsize.



9
10
11
# File 'lib/active_logger/formatters/syslog.rb', line 9

def maxsize
  @maxsize
end

Instance Method Details

#call(severity, timestamp, progname, msg) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/active_logger/formatters/syslog.rb', line 33

def call(severity, timestamp, progname, msg)
  message = "#{tags_text}#{msg}"
  program = progname || default_progname

  syslog_packet(
    tag: program.delete(' '),
    content: message,
    time: timestamp,
    severity: LevelMap.new[severity],
    facility: @facility,
    maxsize: @maxsize || 1024,
    host: @hostname
  )
end

#syslog_packet(tag:, content:, facility: nil, time: nil, severity: nil, host: nil, maxsize: nil) ⇒ Object



48
49
50
51
52
53
54
55
56
57
# File 'lib/active_logger/formatters/syslog.rb', line 48

def syslog_packet(tag:, content:, facility: nil, time: nil, severity: nil, host: nil, maxsize: nil)
  packet          = SyslogProtocol::Packet.new
  packet.hostname = host || `hostname`.chomp
  packet.facility = facility || 'user'
  packet.tag      = tag
  packet.content  = content
  packet.time     = time
  packet.severity = severity || 'notice'
  maxsize ? packet.assemble(maxsize) : packet.assemble
end