From d2a86fef18c12fe3550efe0ca6a01703be7639f9 Mon Sep 17 00:00:00 2001 From: Gianluca Arbezzano Date: Mon, 13 Mar 2017 23:29:58 +0000 Subject: [PATCH] Format logrus has json --- api/events.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/api/events.go b/api/events.go index 56b70ae..8f70194 100644 --- a/api/events.go +++ b/api/events.go @@ -10,11 +10,13 @@ import ( func Events(eventChannel chan *logrus.Entry) func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) { logrus.Info("New events") + formatter := &logrus.JSONFormatter{} flusher, _ := w.(http.Flusher) for { e := <-eventChannel - fmt.Fprintf(w, "Ciao %d\n", e.Message) - flusher.Flush() // Trigger "chunked" encoding and send a chunk... + b, _ := formatter.Format(e) + fmt.Fprintf(w, string(b)) + flusher.Flush() } } }