Class: SyslogTls::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/syslog_tls/protocol.rb

Overview

Message represents full message that can be sent to syslog

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMessage

Returns a new instance of Message.



117
118
119
120
# File 'lib/syslog_tls/protocol.rb', line 117

def initialize
  @msg = ''
  @structured_data = []
end

Instance Attribute Details

#headerObject



122
123
124
# File 'lib/syslog_tls/protocol.rb', line 122

def header
  @header ||= Header.new
end

#msgObject

Returns the value of attribute msg.



114
115
116
# File 'lib/syslog_tls/protocol.rb', line 114

def msg
  @msg
end

#structured_dataObject

Returns the value of attribute structured_data.



114
115
116
# File 'lib/syslog_tls/protocol.rb', line 114

def structured_data
  @structured_data
end

Instance Method Details

#assembleObject



126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/syslog_tls/protocol.rb', line 126

def assemble
  # Start with header
  out = [header.to_s]
  # Add all structured data
  if structured_data.length > 0
    out << structured_data.map(&:to_s).join('')
  else
    out << NIL_VALUE
  end
  # Add message
  out << msg if msg.length > 0
  # Message must end with new line delimiter
  out.join(' ') + "\n"
end

#to_sObject



141
142
143
# File 'lib/syslog_tls/protocol.rb', line 141

def to_s
  assemble
end