) BeforeEach(func() { originalStdout = os.Stdout stdoutReader, os.Stdout, _ = os.Pipe() sink = log.NewCliSink(lager.INFO) }) AfterEach(func() { os.Stdout = originalStdout }) Describe(".Log", func() { Context("when the payload doesn't have lager data with event key", func() { It("does not write to stdout", func() { sink.Log(lager.INFO, []byte("Logging to stdout")) os.Stdout.Close() output, _ := ioutil.ReadAll(stdoutReader) Expect(string(output)).To(Equal("")) }) }) Context("when payload has lager data with event key", func() { It("prints a prettified message to stdout", func() { message := ` { "timestamp":"1431625200.765033007", "source":"backup", "message":"backup.backup_main", "log_level":1,
var sink lager.Sink var writer *copyWriter BeforeSuite(func() { runtime.GOMAXPROCS(MaxThreads) }) BeforeEach(func() { writer = NewCopyWriter() sink = lager.NewWriterSink(writer, lager.INFO) }) Context("when logging above the minimum log level", func() { BeforeEach(func() { sink.Log(lager.INFO, []byte("hello world")) }) It("writes to the given writer", func() { Expect(writer.Copy()).To(Equal([]byte("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(writer.Copy()).To(Equal([]byte{})) })