Open greenpau opened 4 years ago
Is it possible to set generic format? as opposed to being specific.
server.SetFormat(syslog.RFC3164) //server.SetFormat(syslog.RFC5424) //server.SetFormat(syslog.RFC6587)
Code:
import ( //"fmt" "github.com/davecgh/go-spew/spew" syslog "github.com/mcuadros/go-syslog" ) func startSyslogReceiver(r *Receiver, ctx *mgmtContext) { channel := make(syslog.LogPartsChannel) handler := syslog.NewChannelHandler(channel) server := syslog.NewServer() server.SetFormat(syslog.RFC5424) server.SetHandler(handler) server.ListenUDP("0.0.0.0:10514") server.Boot() go func(channel syslog.LogPartsChannel, ctx *mgmtContext) { for logParts := range channel { spew.Dump(logParts) m := Message{} // send the message to shared message bus ctx.MessageBus[1] <- m } }(channel, ctx) server.Wait() }
Sending a message:
logger --server 127.0.0.1 --udp --port 10514 -p 6 -- test UDP syslog from console `date`
Received:
(format.LogParts) (len=13) { (string) (len=7) "message": (string) "", (string) (len=6) "client": (string) (len=15) "127.0.0.1:40626", (string) (len=7) "version": (int) 0, (string) (len=8) "app_name": (string) "", (string) (len=7) "proc_id": (string) "", (string) (len=6) "msg_id": (string) "", (string) (len=8) "hostname": (string) "", (string) (len=15) "structured_data": (string) "", (string) (len=8) "tls_peer": (string) "", (string) (len=8) "priority": (int) 0, (string) (len=8) "facility": (int) 0, (string) (len=8) "severity": (int) 0, (string) (len=9) "timestamp": (time.Time) 0001-01-01 00:00:00 +0000 UTC }
The logger command send messages in RFC3164. Therefore, that format needs to be set.
logger
RFC3164
Is it possible to set generic format? as opposed to being specific.
Code:
Sending a message:
Received: