circolog/formatter/rfc.go

49 lines
997 B
Go

package formatter
import (
"errors"
syslog "gopkg.in/mcuadros/go-syslog.v2"
"gopkg.in/mcuadros/go-syslog.v2/format"
)
// SyslogRFC is the formatter that the server should use
type SyslogRFC struct{ format.Format }
func (rfc *SyslogRFC) Set(v string) error {
newval, err := parseRFCValue(v)
if err != nil {
return err
}
rfc.Format = newval
return nil
}
func (rfc *SyslogRFC) String() string {
switch {
case rfc.Format == syslog.Automatic:
return "auto"
case rfc.Format == syslog.RFC3164:
return "rfc3164"
case rfc.Format == syslog.RFC5424:
return "rfc5424"
}
return ""
}
func parseRFCValue(v string) (format.Format, error) {
switch {
case v == "rfc3164":
return syslog.RFC3164, nil
case v == "rfc5424":
return syslog.RFC5424, nil
case v == "auto":
return syslog.Automatic, nil
default:
return nil, ErrRFCNotSupported
}
}
// ErrRFCNotSupported is raised if the supplied rfc string is
// not recognized.
var ErrRFCNotSupported = errors.New("RFC not known")