Syslog
Jump to navigation
Jump to search
echo "test" | nc -v -u -w 0 127.0.0.1 9514
echo "<3>Oct 11 22:14:15 wjd1-busku foo2testing" | nc -v -u -w 0 log.example.com 514
logger --udp --port 9514 -n 127.0.0.1 "Test message"
https://github.com/jeremybusk/go-syslog
go mod init a go get gopkg.in/mcuadros/go-syslog.v2
log.go
package main import ( "fmt" "gopkg.in/mcuadros/go-syslog.v2" ) func main() { channel := make(syslog.LogPartsChannel) handler := syslog.NewChannelHandler(channel) server := syslog.NewServer() server.SetFormat(syslog.RFC5424) server.SetHandler(handler) server.ListenUDP("0.0.0.0:9514") server.ListenTCP("0.0.0.0:9514") server.Boot() go func(channel syslog.LogPartsChannel) { for logParts := range channel { fmt.Println(logParts) } }(channel) server.Wait() }
go build log