small cleanup
This commit is contained in:
parent
3132a18164
commit
432d46d15f
1 changed files with 18 additions and 18 deletions
36
main.go
36
main.go
|
@ -20,13 +20,27 @@ func syslogdHandler(channel syslog.LogPartsChannel) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func httpHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
circbuf.Do(func(x interface{}) {
|
||||||
|
if x == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
logmsg := x.(format.LogParts)
|
||||||
|
if logmsg["message"] == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c := logmsg["message"].(string)
|
||||||
|
w.Write([]byte(c))
|
||||||
|
w.Write([]byte("\n"))
|
||||||
|
})
|
||||||
|
}
|
||||||
func main() {
|
func main() {
|
||||||
syslogSocketPath := flag.String("syslogd-socket", "", "The socket to listen to syslog addresses")
|
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")
|
// 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")
|
bufsize := flag.Int("buffer-size", 1000, "Number of messages to keep")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
channel := make(syslog.LogPartsChannel)
|
channel := make(chan format.LogParts)
|
||||||
handler := syslog.NewChannelHandler(channel)
|
handler := syslog.NewChannelHandler(channel)
|
||||||
|
|
||||||
server := syslog.NewServer()
|
server := syslog.NewServer()
|
||||||
|
@ -34,28 +48,14 @@ func main() {
|
||||||
server.SetHandler(handler)
|
server.SetHandler(handler)
|
||||||
if *syslogSocketPath != "" {
|
if *syslogSocketPath != "" {
|
||||||
server.ListenUnixgram(*syslogSocketPath)
|
server.ListenUnixgram(*syslogSocketPath)
|
||||||
|
} else {
|
||||||
|
server.ListenUDP("127.0.0.1:9514")
|
||||||
}
|
}
|
||||||
server.ListenUDP("127.0.0.1:9514")
|
|
||||||
circbuf = ring.New(*bufsize)
|
circbuf = ring.New(*bufsize)
|
||||||
server.Boot()
|
server.Boot()
|
||||||
|
|
||||||
go syslogdHandler(channel)
|
go syslogdHandler(channel)
|
||||||
|
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/", httpHandler)
|
||||||
circbuf.Do(func(x interface{}) {
|
|
||||||
if x == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
logmsg := x.(format.LogParts)
|
|
||||||
if logmsg["message"] == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
c := logmsg["message"].(string)
|
|
||||||
w.Write([]byte(c))
|
|
||||||
w.Write([]byte("\n"))
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
http.ListenAndServe(":9080", nil)
|
http.ListenAndServe(":9080", nil)
|
||||||
|
|
||||||
server.Wait()
|
server.Wait()
|
||||||
|
|
Loading…
Reference in a new issue