The aim of this PR is to introduce a syslog builder based on ragel.
This way, using the builder API, the user can create syslog messages which parts are syntactically and semantically valid.
Incorrect input values during the creation are ignored.
The builder accounts also for nil values, distinguishing them from 0-values.
it has a fluent interface, to be able to chain setters.
To do so I extracted the RFC5424 common pieces into a base ragel grammar which is then used within the parser and within the builder.
The API is:
[x] SetPriority(value uint8) *SyslogMessage // not using the parser
[x] SetVersion(value uint16) *SyslogMessage // not using the parser
[x] SetTimestamp(value string) *SyslogMessage
[x] SetHostname(value string) *SyslogMessage
[x] SetAppname(value string) *SyslogMessage
[x] SetProcID(value string) *SyslogMessage
[x] SetMsgID(value string) *SyslogMessage
[x] SetElementID(value string) *SyslogMessage
[x] SetParameter(element string, name string, value string) *SyslogMessage
[x] SetMessage(value string) *SyslogMessage
With this we could make the SyslogMessage struct fields private, providing getters (as done for facility and severity) to access their values and forcing the user to use the builder API to construct SyslogMessage instances. What do you think about this @goller ?
Other notable methods of SyslogMessage are:
[x] Valid() bool
[x] String() string // serialization into a valid syslog message
Other methods we could introduce but I am not sure about are:
SetPrival(value string)
SetTime(value time.Time) // reducing time.Time to a valid RFC3339 micro timestamp
The aim of this PR is to introduce a syslog builder based on ragel.
This way, using the builder API, the user can create syslog messages which parts are syntactically and semantically valid.
Incorrect input values during the creation are ignored. The builder accounts also for nil values, distinguishing them from 0-values. it has a fluent interface, to be able to chain setters.
To do so I extracted the RFC5424 common pieces into a base ragel grammar which is then used within the parser and within the builder.
The API is:
SetPriority(value uint8) *SyslogMessage // not using the parser
SetVersion(value uint16) *SyslogMessage // not using the parser
SetTimestamp(value string) *SyslogMessage
SetHostname(value string) *SyslogMessage
SetAppname(value string) *SyslogMessage
SetProcID(value string) *SyslogMessage
SetMsgID(value string) *SyslogMessage
SetElementID(value string) *SyslogMessage
SetParameter(element string, name string, value string) *SyslogMessage
SetMessage(value string) *SyslogMessage
With this we could make the
SyslogMessage
struct fields private, providing getters (as done for facility and severity) to access their values and forcing the user to use the builder API to constructSyslogMessage
instances. What do you think about this @goller ?Other notable methods of
SyslogMessage
are:Valid() bool
String() string // serialization into a valid syslog message
Other methods we could introduce but I am not sure about are:
SetPrival(value string)
SetTime(value time.Time)
// reducingtime.Time
to a valid RFC3339 micro timestamp