Class: Progstr::LogMessage
- Inherits:
-
Object
- Object
- Progstr::LogMessage
- Defined in:
- lib/progstr/log_message.rb
Constant Summary collapse
- LEVELS =
{ :info => 0, :warning => 1, :error => 2, :fatal => 3 }
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Instance Method Summary collapse
- #encode_time(time) ⇒ Object
- #get_host(host) ⇒ Object
-
#initialize(params) ⇒ LogMessage
constructor
A new instance of LogMessage.
- #to_hash ⇒ Object
Constructor Details
#initialize(params) ⇒ LogMessage
Returns a new instance of LogMessage.
8 9 10 11 12 13 14 |
# File 'lib/progstr/log_message.rb', line 8 def initialize(params) @text = params[:text] @source = params[:source] @host = params[:host] @level = params[:level] @time = params[:time] end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
6 7 8 |
# File 'lib/progstr/log_message.rb', line 6 def host @host end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
6 7 8 |
# File 'lib/progstr/log_message.rb', line 6 def level @level end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
6 7 8 |
# File 'lib/progstr/log_message.rb', line 6 def source @source end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
6 7 8 |
# File 'lib/progstr/log_message.rb', line 6 def text @text end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
6 7 8 |
# File 'lib/progstr/log_message.rb', line 6 def time @time end |
Instance Method Details
#encode_time(time) ⇒ Object
20 21 22 23 |
# File 'lib/progstr/log_message.rb', line 20 def encode_time(time) time ||= Time.now (time.to_f * 1000).to_i end |
#get_host(host) ⇒ Object
25 26 27 |
# File 'lib/progstr/log_message.rb', line 25 def get_host(host) host || Socket.gethostname || ENV["HOST"] || "Unknown" end |
#to_hash ⇒ Object
16 17 18 |
# File 'lib/progstr/log_message.rb', line 16 def to_hash {:text => @text, :source => @source, :host => get_host(@host), :level => LEVELS[@level], :time => encode_time(@time)} end |