small cleanup
This commit is contained in:
parent
3132a18164
commit
432d46d15f
1 changed files with 18 additions and 18 deletions
46
main.go
46
main.go
|
@ -20,28 +20,7 @@ func syslogdHandler(channel syslog.LogPartsChannel) {
|
|||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
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")
|
||||
flag.Parse()
|
||||
|
||||
channel := make(syslog.LogPartsChannel)
|
||||
handler := syslog.NewChannelHandler(channel)
|
||||
|
||||
server := syslog.NewServer()
|
||||
server.SetFormat(syslog.RFC5424)
|
||||
server.SetHandler(handler)
|
||||
if *syslogSocketPath != "" {
|
||||
server.ListenUnixgram(*syslogSocketPath)
|
||||
}
|
||||
server.ListenUDP("127.0.0.1:9514")
|
||||
circbuf = ring.New(*bufsize)
|
||||
server.Boot()
|
||||
|
||||
go syslogdHandler(channel)
|
||||
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
func httpHandler(w http.ResponseWriter, r *http.Request) {
|
||||
circbuf.Do(func(x interface{}) {
|
||||
if x == nil {
|
||||
return
|
||||
|
@ -54,8 +33,29 @@ func main() {
|
|||
w.Write([]byte(c))
|
||||
w.Write([]byte("\n"))
|
||||
})
|
||||
})
|
||||
}
|
||||
func main() {
|
||||
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")
|
||||
flag.Parse()
|
||||
|
||||
channel := make(chan format.LogParts)
|
||||
handler := syslog.NewChannelHandler(channel)
|
||||
|
||||
server := syslog.NewServer()
|
||||
server.SetFormat(syslog.RFC5424)
|
||||
server.SetHandler(handler)
|
||||
if *syslogSocketPath != "" {
|
||||
server.ListenUnixgram(*syslogSocketPath)
|
||||
} else {
|
||||
server.ListenUDP("127.0.0.1:9514")
|
||||
}
|
||||
circbuf = ring.New(*bufsize)
|
||||
server.Boot()
|
||||
go syslogdHandler(channel)
|
||||
|
||||
http.HandleFunc("/", httpHandler)
|
||||
http.ListenAndServe(":9080", nil)
|
||||
|
||||
server.Wait()
|
||||
|
|
Loading…
Reference in a new issue