Class: Fiva::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/fiva/message.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(level, msg, **data) ⇒ Message

Returns a new instance of Message.



5
6
7
8
9
10
# File 'lib/fiva/message.rb', line 5

def initialize(level, msg, **data)
  @timestamp = DateTime.now
  @level = level
  @msg   = msg
  @data  = data
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



3
4
5
# File 'lib/fiva/message.rb', line 3

def data
  @data
end

#levelObject

Returns the value of attribute level.



3
4
5
# File 'lib/fiva/message.rb', line 3

def level
  @level
end

#msgObject

Returns the value of attribute msg.



3
4
5
# File 'lib/fiva/message.rb', line 3

def msg
  @msg
end

#timestampObject

Returns the value of attribute timestamp.



3
4
5
# File 'lib/fiva/message.rb', line 3

def timestamp
  @timestamp
end

Instance Method Details

#to_hashObject



12
13
14
15
16
17
18
19
# File 'lib/fiva/message.rb', line 12

def to_hash
  {
    timestamp: @timestamp,
    level:     @level,
    msg:       @msg,
    data:      @data
  }
end

#to_jsonObject



21
22
23
# File 'lib/fiva/message.rb', line 21

def to_json
  self.to_hash.to_json
end