digitalocean / captainslog

A Syslog Protocol Parser
Mozilla Public License 2.0
136 stars 19 forks source link

Problem: sometimes dont want to parse json #49

Closed taotetek closed 7 years ago

taotetek commented 7 years ago

Sometimes we want to parse "cee" rfc3164 messages without parsing the JSON in the message body. If we just want access to syslog headers, not parsing the JSON saves quite a bit of time. This PR adds an optional function argument ( "OptionDontParseJSON" ) that may be passed to the NewParser and NewSyslogMsg constructors to tell the parser to save "cee" message content without actually parsing it.

If JSON values are added to the message after the original parse, and SyslogMsg.String(), SyslogMsg.Bytes(), or SyslogMsg.JSON() are called, the message content will be parsed at that time in order to combine the fields within it with any fields added to SyslogMsg.JSONValues. Otherwise, SyslogMsg.Content will be used without ever incurring the penalty of a JSON parse.

This PR also fixes some minor golint / go vet issues.