This parser uses the Parslet to define rules for parsing a log message in the simple key=value
format used by Heroku, eg:
at=error code=H12 desc="Request timeout" method=GET path="/foo" dyno=web.3 connect=1ms service=30000ms status=503 bytes=0
Given a message in the above format, the parser returns a hash of the key/value pairs:
message = 'at=error code=H12 desc="Request timeout" method=GET...'
Parser.parse(message)
#=> { at: "error", code: "H12", desc: "Request timeout", method: "GET, ... }
Some of the values are quoted strings that contains spaces (desc="Request timeout"
) so you can't just use message.split(" ")
or a regular expression. I was unable to find an existing parser for this format so, execution speed not being a critical factor, I explored Ruby parser generators. Parslet features a very readable DSL and was very easy to work with.