Compare commits

..

1 commit

Author SHA1 Message Date
55827916bb
Add flag to set syslog format. 2019-05-02 12:28:33 +02:00
2 changed files with 8 additions and 9 deletions

View file

@ -26,7 +26,7 @@ func cleanSocket(socket string) {
func main() {
var err error
var logFmt formatter.SyslogRFC
logFmt.Fmt = syslog.Automatic
logFmt.Format = syslog.Automatic
syslogSocketPath := flag.String("syslogd-socket", "", "The socket to listen to syslog addresses")
// dumpSocketPath := flag.String("dump-socket", "/run/buffer.sock", "The socket that user will connect to in order to receive logs")
bufsize := flag.Int("buffer-size", 1000, "Number of messages to keep")
@ -47,7 +47,8 @@ func main() {
go hub.Run()
server := syslog.NewServer()
server.SetFormat(logFmt.Fmt)
server.SetFormat(logFmt.Format)
fmt.Printf("Syslog format set to: %s\n", logFmt.String())
server.SetHandler(handler)
if *syslogSocketPath != "" {
if err = server.ListenUnixgram(*syslogSocketPath); err != nil {

View file

@ -8,26 +8,24 @@ import (
)
// SyslogRFC is the formatter that the server should use
type SyslogRFC struct {
Fmt format.Format
}
type SyslogRFC struct{ format.Format }
func (rfc *SyslogRFC) Set(v string) error {
newval, err := parseRFCValue(v)
if err != nil {
return err
}
rfc.Fmt = newval
rfc.Format = newval
return nil
}
func (rfc *SyslogRFC) String() string {
switch {
case rfc.Fmt == syslog.Automatic:
case rfc.Format == syslog.Automatic:
return "auto"
case rfc.Fmt == syslog.RFC3164:
case rfc.Format == syslog.RFC3164:
return "rfc3164"
case rfc.Fmt == syslog.RFC5424:
case rfc.Format == syslog.RFC5424:
return "rfc5424"
}
return ""