func Handler(sink *lager.ReconfigurableSink) http.Handler { mux := http.NewServeMux() mux.Handle("/debug/pprof/", http.HandlerFunc(pprof.Index)) mux.Handle("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline)) mux.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile)) mux.Handle("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol)) mux.Handle("/log-level", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { level, err := ioutil.ReadAll(r.Body) if err != nil { return } switch string(level) { case "debug", "DEBUG", "d", strconv.Itoa(int(lager.DEBUG)): sink.SetMinLevel(lager.DEBUG) case "info", "INFO", "i", strconv.Itoa(int(lager.INFO)): sink.SetMinLevel(lager.INFO) case "error", "ERROR", "e", strconv.Itoa(int(lager.ERROR)): sink.SetMinLevel(lager.ERROR) case "fatal", "FATAL", "f", strconv.Itoa(int(lager.FATAL)): sink.SetMinLevel(lager.FATAL) } })) return mux }
It("writes to the given sink", func() { Expect(testSink.Buffer()).To(gbytes.Say("hello world\n")) }) }) Context("when logging below the minimum log level", func() { BeforeEach(func() { sink.Log(lager.DEBUG, []byte("hello world")) }) It("does not write to the given writer", func() { Expect(testSink.Buffer().Contents()).To(BeEmpty()) }) }) Context("when reconfigured to a new log level", func() { BeforeEach(func() { sink.SetMinLevel(lager.DEBUG) }) It("writes logs above the new log level", func() { sink.Log(lager.DEBUG, []byte("hello world")) Expect(testSink.Buffer()).To(gbytes.Say("hello world\n")) }) It("returns the newly updated level", func() { Expect(sink.GetMinLevel()).To(Equal(lager.DEBUG)) }) }) })