Class: Pebble::Watch::LogEvent

Inherits:
Event
  • Object
show all
Defined in:
lib/pebble/watch/log_event.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



6
7
8
# File 'lib/pebble/watch/log_event.rb', line 6

def filename
  @filename
end

#levelObject

Returns the value of attribute level.



5
6
7
# File 'lib/pebble/watch/log_event.rb', line 5

def level
  @level
end

#linenumberObject

Returns the value of attribute linenumber.



7
8
9
# File 'lib/pebble/watch/log_event.rb', line 7

def linenumber
  @linenumber
end

#messageObject

Returns the value of attribute message.



8
9
10
# File 'lib/pebble/watch/log_event.rb', line 8

def message
  @message
end

#timestampObject

Returns the value of attribute timestamp.



4
5
6
# File 'lib/pebble/watch/log_event.rb', line 4

def timestamp
  @timestamp
end

Class Method Details

.parse(raw_message) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/pebble/watch/log_event.rb', line 10

def self.parse(raw_message)
  return nil if raw_message.length < 8

  timestamp, level, message_size, linenumber = raw_message[0, 8].unpack("L>CCS>")
  filename  = raw_message[8, 16]
  message   = raw_message[24, message_size]

  log_levels = {
    1   => :error,
    50  => :warning,
    100 => :info,
    200 => :debug,
    250 => :verbose
  }

  event = new

  event.timestamp   = Time.at(timestamp)
  event.level       = log_levels[level] || :unknown
  event.linenumber  = linenumber
  event.filename    = filename
  event.message     = message

  event
end

Instance Method Details

#inspectObject



36
37
38
# File 'lib/pebble/watch/log_event.rb', line 36

def inspect
  "[#{self.level.to_s.capitalize}] #{self.message}"
end