Class: Logplex::Message
- Inherits:
-
Object
- Object
- Logplex::Message
- 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'.freeze
- FIELD_DISABLED =
'-'.freeze
Instance Method Summary collapse
-
#initialize(message, opts = {}) ⇒ Message
constructor
A new instance of Message.
- #syslog_frame ⇒ Object
- #validate ⇒ Object
Constructor Details
#initialize(message, opts = {}) ⇒ Message
Returns a new instance of Message.
15 16 17 18 19 20 21 22 |
# File 'lib/logplex/message.rb', line 15 def initialize(, opts = {}) @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_frame ⇒ Object
24 25 26 27 28 |
# File 'lib/logplex/message.rb', line 24 def syslog_frame temp = "#{FACILITY_AND_PRIORITY} #{formatted_time} #{@host} #{@app_name} #{@process} #{@message_id} #{FIELD_DISABLED} #{}" length = temp.length "#{length} #{temp}" end |
#validate ⇒ Object
30 31 32 33 34 35 |
# File 'lib/logplex/message.rb', line 30 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 |