Class: Logplex::Message

Inherits:
Object
  • Object
show all
Includes:
Valcro
Defined in:
lib/logplex/message.rb

Constant Summary collapse

FACILITY_AND_PRIORITY =

facility = local0, priority = info, RFC5452 encoded syslog version 1

"<134>1"
FIELD_DISABLED =
"-"

Instance Method Summary collapse

Constructor Details

#initialize(message, opts = {}) ⇒ Message

Returns a new instance of Message.



17
18
19
20
21
22
23
24
# File 'lib/logplex/message.rb', line 17

def initialize(message, opts = {})
  @message = message
  @app_name = opts[:app_name] || Logplex.configuration.app_name
  @time = opts[:time] || DateTime.now
  @process = opts[:process] || Logplex.configuration.process
  @host = opts[:host] || Logplex.configuration.host
  @message_id = opts[:message_id] || FIELD_DISABLED
end

Instance Method Details

#syslog_frameObject



26
27
28
29
30
# File 'lib/logplex/message.rb', line 26

def syslog_frame
  temp = "#{FACILITY_AND_PRIORITY} #{formatted_time} #{@host} #{@app_name} #{@process} #{@message_id} #{FIELD_DISABLED} #{formatted_message}"
  length = temp.length
  "#{length} #{temp}"
end

#validateObject



32
33
34
35
36
37
# File 'lib/logplex/message.rb', line 32

def validate
  super
  errors.add(:message, "too long") if @message.length > 10240
  errors.add(:process, "can't be nil") if @process.nil?
  errors.add(:host, "can't be nil") if @host.nil?
end