1
0
Fork 0
forked from boyska/circolog

Add flag to set syslog format.

This commit is contained in:
Blallo 2019-05-01 15:55:41 +02:00
parent d3799d19f9
commit 76a6381516
No known key found for this signature in database
GPG key ID: 0CBE577C9B72DC3F

View file

@ -22,6 +22,20 @@ func cleanSocket(socket string) {
}
}
func setSyslogFormat(server *syslog.Server, format string) {
switch {
case format == "auto":
server.SetFormat(syslog.Automatic)
case format == "rfc3164":
server.SetFormat(syslog.RFC3164)
case format == "rfc5424":
server.SetFormat(syslog.RFC5424)
}
// TODO: propose a patch to mcuadros/go-syslog.v2
// to get the format from the server itself.
log.Printf("Syslog format set to: %s\n", format)
}
func main() {
var err error
syslogSocketPath := flag.String("syslogd-socket", "", "The socket to listen to syslog addresses")
@ -31,6 +45,7 @@ func main() {
queryAddr := flag.String("query-addr", "127.0.0.1:9080", "Address:port where to bind the query service")
querySocket := flag.String("query-socket", "", "Path to a unix domain socket for the HTTP server; recommended for security reasons!")
ctlSocket := flag.String("ctl-socket", "/tmp/circologd-ctl.sock", "Path to a unix domain socket for the control server; leave empty to disable")
logFmt := flag.String("log-fmt", "auto", "Log messages format. If not set, defaults to automatic choice. Allowed values: rfc3164, rfc5424.")
verbose := flag.Bool("verbose", false, "Print more output executing the daemon")
debug := flag.Bool("debug", false, "Print debugging info executing the daemon")
flag.Parse()
@ -43,7 +58,7 @@ func main() {
go hub.Run()
server := syslog.NewServer()
server.SetFormat(syslog.Automatic)
setSyslogFormat(server, *logFmt)
server.SetHandler(handler)
if *syslogSocketPath != "" {
if err = server.ListenUnixgram(*syslogSocketPath); err != nil {