Class: Woodchuck::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/woodchuck/event.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, line) ⇒ Event

Returns a new instance of Event.



7
8
9
10
11
12
13
14
15
16
# File 'lib/woodchuck/event.rb', line 7

def initialize(path, line)
  @path = path
  @line = line
  @host = Socket.gethostname
  @timestamp = Time.now.utc.iso8601(6)
  @source = Addressable::URI.new(:scheme => 'file', :host => host, :path => path)
  @message = line.strip
  @fields = {}
  @tags = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args, &block) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/woodchuck/event.rb', line 18

def method_missing(symbol, *args, &block)
  if to_hash.has_key?(symbol)
    to_hash
  else
    super(symbol, *args, &block)
  end
end

Instance Attribute Details

#fieldsObject

Returns the value of attribute fields.



5
6
7
# File 'lib/woodchuck/event.rb', line 5

def fields
  @fields
end

#hostObject

Returns the value of attribute host.



5
6
7
# File 'lib/woodchuck/event.rb', line 5

def host
  @host
end

#lineObject

Returns the value of attribute line.



5
6
7
# File 'lib/woodchuck/event.rb', line 5

def line
  @line
end

#messageObject

Returns the value of attribute message.



5
6
7
# File 'lib/woodchuck/event.rb', line 5

def message
  @message
end

#pathObject

Returns the value of attribute path.



5
6
7
# File 'lib/woodchuck/event.rb', line 5

def path
  @path
end

#sourceObject

Returns the value of attribute source.



5
6
7
# File 'lib/woodchuck/event.rb', line 5

def source
  @source
end

#tagsObject

Returns the value of attribute tags.



5
6
7
# File 'lib/woodchuck/event.rb', line 5

def tags
  @tags
end

#timestampObject

Returns the value of attribute timestamp.



5
6
7
# File 'lib/woodchuck/event.rb', line 5

def timestamp
  @timestamp
end

Instance Method Details

#to_hashObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/woodchuck/event.rb', line 26

def to_hash
  {
    '@source' => source.to_s,
    '@type' => source.scheme,
    '@tags' => tags,
    '@fields' => fields,
    '@timestamp' => timestamp,
    '@source_host' => host,
    '@source_path' => path,
    '@message' => message
  }
end

#to_json(*args) ⇒ Object



39
40
41
# File 'lib/woodchuck/event.rb', line 39

def to_json(*args)
  to_hash.to_json(*args)
end

#to_sObject



43
44
45
# File 'lib/woodchuck/event.rb', line 43

def to_s
  to_json
end