Last active
August 29, 2015 13:58
-
-
Save caevyn/9985310 to your computer and use it in GitHub Desktop.
From weird log format to hash. (for logstash filter)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
log = "DateTime: 23/04/1998\r\nI'm just a message\r\nKey: value\r\nIm a url: http://cats.com\r\nError Description: I'm an error here is my stacktrace\r\n at stuff\r\n at more stuff\r\n\key with no value: \r\nI'm another random message line\r\n--------------------------------------------" | |
rows = log.split(/\r\n/).partition{|x| x.start_with?('Error Description: ',' at')} | |
event = {'Error'=>rows[0].join($/).sub('Error Description: ','')} | |
remove = [] | |
rows[1].each do |i| | |
i.scan(/(.+): (.*)/) do |x,y| | |
event[x.delete(' ')] = y | |
remove.push(i) | |
end | |
end | |
event['message'] = rows[1].reject{|x| x.start_with? *remove, '------'}.join($/) | |
print event |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment