Class: LogStash::Event
- Inherits:
-
Object
- Object
- LogStash::Event
- Defined in:
- lib/logstash/event.rb
Overview
General event type. Will expand this in the future.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](key) ⇒ Object
-
#[]=(key, value) ⇒ Object
TODO(sissel): the semantics of [] and []= are now different in that []= only allows you to assign to only fields (not metadata), but [] allows you to read fields and metadata.
- #append(event) ⇒ Object
- #cancel ⇒ Object
- #cancelled? ⇒ Boolean
-
#fields ⇒ Object
def fields.
- #include?(key) ⇒ Boolean
-
#initialize(data = Hash.new) ⇒ Event
constructor
A new instance of Event.
-
#message ⇒ Object
def message.
-
#message=(val) ⇒ Object
def message=.
- #overwrite(event) ⇒ Object
-
#source ⇒ Object
def source.
- #source=(val) ⇒ Object
- #sprintf(format) ⇒ Object
-
#tags ⇒ Object
def tags.
-
#tags=(val) ⇒ Object
def tags=.
-
#timestamp ⇒ Object
def timestamp.
-
#timestamp=(val) ⇒ Object
def timestamp=.
-
#to_hash ⇒ Object
def to_hash.
-
#to_json ⇒ Object
def to_json.
- #to_s ⇒ Object
-
#type ⇒ Object
def type.
-
#type=(val) ⇒ Object
def type=.
Constructor Details
#initialize(data = Hash.new) ⇒ Event
Returns a new instance of Event.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/logstash/event.rb', line 9 def initialize(data=Hash.new) @cancelled = false @data = { "@source" => "unknown", "@type" => nil, "@tags" => [], "@fields" => {}, }.merge(data) if !@data.include?("@timestamp") @data["@timestamp"] = LogStash::Time.now.utc.to_iso8601 end end |
Class Method Details
Instance Method Details
#==(other) ⇒ Object
146 147 148 149 150 151 152 153 |
# File 'lib/logstash/event.rb', line 146 def ==(other) puts "#{self.class.name}#==(#{other.inspect})" if !other.is_a?(self.class) return false end return other.to_hash == self.to_hash end |
#[](key) ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/logstash/event.rb', line 73 def [](key) # If the key isn't in fields and it starts with an "@" sign, get it out of data instead of fields if ! @data["@fields"].has_key?(key) and key.slice(0,1) == "@" return @data[key] # Exists in @fields (returns value) or doesn't start with "@" (return null) else return @data["@fields"][key] end end |
#[]=(key, value) ⇒ Object
TODO(sissel): the semantics of [] and []= are now different in that []= only allows you to assign to only fields (not metadata), but
-
allows you to read fields and metadata.
We should fix this. Metadata is really a namespace issue, anyway.
87 |
# File 'lib/logstash/event.rb', line 87 def []=(key, value); @data["@fields"][key] = value end |
#append(event) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/logstash/event.rb', line 104 def append(event) self. += "\n" + event. self. |= event. # Append all fields event.fields.each do |name, value| if self.fields.include?(name) puts "Merging field #{name}" self.fields[name] |= value else puts "Setting field #{name}" self.fields[name] = value end end # event.fields.each end |
#cancel ⇒ Object
29 30 31 |
# File 'lib/logstash/event.rb', line 29 def cancel @cancelled = true end |
#cancelled? ⇒ Boolean
34 35 36 |
# File 'lib/logstash/event.rb', line 34 def cancelled? return @cancelled end |
#fields ⇒ Object
def fields
88 |
# File 'lib/logstash/event.rb', line 88 def fields; return @data["@fields"] end |
#include?(key) ⇒ Boolean
100 |
# File 'lib/logstash/event.rb', line 100 def include?(key); return @data.include?(key) end |
#message ⇒ Object
def message
60 |
# File 'lib/logstash/event.rb', line 60 def ; @data["@message"]; end |
#message=(val) ⇒ Object
def message=
61 |
# File 'lib/logstash/event.rb', line 61 def (val); @data["@message"] = val; end |
#overwrite(event) ⇒ Object
95 96 97 |
# File 'lib/logstash/event.rb', line 95 def overwrite(event) @data = event.to_hash end |
#source ⇒ Object
def source
48 |
# File 'lib/logstash/event.rb', line 48 def source; @data["@source"]; end |
#source=(val) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/logstash/event.rb', line 49 def source=(val) if val.is_a?(URI) @data["@source"] = val.to_s @data["@source_host"] = val.host @data["@source_path"] = val.path else @data["@source"] = val end end |
#sprintf(format) ⇒ Object
136 137 138 139 140 141 142 143 |
# File 'lib/logstash/event.rb', line 136 def sprintf(format) result = format.gsub(/\$\{[@A-Za-z0-9_-]+\}/) do |match| name = match[2..-2] # trim '${' and '}' value = (self[name] or match) end #$stderr.puts "sprintf(#{format.inspect}) => #{result.inspect}" return result end |
#tags ⇒ Object
def tags
68 |
# File 'lib/logstash/event.rb', line 68 def ; @data["@tags"]; end |
#tags=(val) ⇒ Object
def tags=
69 |
# File 'lib/logstash/event.rb', line 69 def (val); @data["@tags"] = val; end |
#timestamp ⇒ Object
def timestamp
44 |
# File 'lib/logstash/event.rb', line 44 def ; @data["@timestamp"]; end |
#timestamp=(val) ⇒ Object
def timestamp=
45 |
# File 'lib/logstash/event.rb', line 45 def (val); @data["@timestamp"] = val; end |
#to_hash ⇒ Object
def to_hash
92 |
# File 'lib/logstash/event.rb', line 92 def to_hash; return @data end |
#to_json ⇒ Object
def to_json
91 |
# File 'lib/logstash/event.rb', line 91 def to_json; return @data.to_json end |
#to_s ⇒ Object
39 40 41 |
# File 'lib/logstash/event.rb', line 39 def to_s return "#{} #{source}: #{}" end |
#type ⇒ Object
def type
64 |
# File 'lib/logstash/event.rb', line 64 def type; @data["@type"]; end |
#type=(val) ⇒ Object
def type=
65 |
# File 'lib/logstash/event.rb', line 65 def type=(val); @data["@type"] = val; end |