Change event '[]' method to check @data (not just @data[@fields]) if the key starts with '@' so that grep filtering can match standard parse values

This commit is contained in:
ec2 2011-01-22 09:53:31 +00:00
parent b1ed54d286
commit d1013465b9

View file

@ -70,7 +70,16 @@ class LogStash::Event
# field-related access # field-related access
public public
def [](key); @data["@fields"][key] end # def [] 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) == "@"
@data[key]
# Exists in @fields (returns value) or doesn't start with "@" (return null)
else
@data["@fields"][key]
end
end # def []
def []=(key, value); @data["@fields"][key] = value end # def []= def []=(key, value); @data["@fields"][key] = value end # def []=
def fields; return @data["@fields"] end # def fields def fields; return @data["@fields"] end # def fields