Format logrus has json

This commit is contained in:
Gianluca Arbezzano 2017-03-13 23:29:58 +00:00
parent 1709cf5150
commit d2a86fef18

View File

@ -10,11 +10,13 @@ import (
func Events(eventChannel chan *logrus.Entry) func(w http.ResponseWriter, r *http.Request) { func Events(eventChannel chan *logrus.Entry) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
logrus.Info("New events") logrus.Info("New events")
formatter := &logrus.JSONFormatter{}
flusher, _ := w.(http.Flusher) flusher, _ := w.(http.Flusher)
for { for {
e := <-eventChannel e := <-eventChannel
fmt.Fprintf(w, "Ciao %d\n", e.Message) b, _ := formatter.Format(e)
flusher.Flush() // Trigger "chunked" encoding and send a chunk... fmt.Fprintf(w, string(b))
flusher.Flush()
} }
} }
} }