lib/logstash/codecs/google_appengine.rb in logstash-codec-google_appengine-1.7.0 vs lib/logstash/codecs/google_appengine.rb in logstash-codec-google_appengine-1.10.0
- old
+ new
@@ -13,21 +13,21 @@
@json = LogStash::Codecs::JSON.new
end
def decode(data)
begin
- @json.decode(data) do |json|
- if is_parse_failure(json)
- return @logger.error("Failed to process data", :data => json)
+ @json.decode data do |json|
+ if is_parse_failure json
+ @logger.error("Failed to process data", :data => json)
+ else
+ flatten(json).each { |flattenedJson|
+ yield LogStash::Event.new flattenedJson
+ }
end
-
- flatten(json).each { |flattenedJson|
- yield LogStash::Event.new(flattenedJson)
- }
end
rescue => e
- @logger.error("Failed to process data", :error => e, :data => data)
+ @logger.error "Failed to process data", :error => e, :data => data
end
end
end
private
@@ -37,19 +37,22 @@
end
def flatten(event)
payload = event['protoPayload']
lines = payload['line']
- payload.delete('@type')
+
+ payload.delete '@type'
+ payload['id'] = payload['requestId']
+
if lines
- payload.delete('line')
+ payload.delete 'line'
lines.map.with_index { |line, i|
- merged = payload.merge(line)
- merged['lineId'] = merged['requestId'] + i.to_s
+ merged = payload.merge line
+ merged['id'] = merged['id'] + i.to_s
+ merged['message'] = merged.delete 'logMessage'
merged
}
else
payload['time'] = payload['endTime']
- payload['lineId'] = payload['requestId']
[payload]
end
end