Class: SumologicCloudSyslog::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/sumologic_cloud_syslog/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.



113
114
115
116
117
# File 'lib/sumologic_cloud_syslog/protocol.rb', line 113

def initialize
  @msg = ''
  @structured_data = []
  @header = Header.new
end

Instance Attribute Details

#headerObject

Returns the value of attribute header.



111
112
113
# File 'lib/sumologic_cloud_syslog/protocol.rb', line 111

def header
  @header
end

#msgObject

Returns the value of attribute msg.



111
112
113
# File 'lib/sumologic_cloud_syslog/protocol.rb', line 111

def msg
  @msg
end

#structured_dataObject

Returns the value of attribute structured_data.



111
112
113
# File 'lib/sumologic_cloud_syslog/protocol.rb', line 111

def structured_data
  @structured_data
end

Instance Method Details

#assembleObject



119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/sumologic_cloud_syslog/protocol.rb', line 119

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 << SumologicCloudSyslog::NIL_VALUE
  end
  # Add message
  out << msg if msg.length > 0
  # Message must end with new line delimiter
  out.join(' ') + "\n"
end

#to_sObject



134
135
136
# File 'lib/sumologic_cloud_syslog/protocol.rb', line 134

def to_s
  assemble
end