func main() { consumer := consumer.New(dopplerAddress, &tls.Config{InsecureSkipVerify: true}, nil) consumer.SetDebugPrinter(ConsoleDebugPrinter{}) messages, err := consumer.RecentLogs(appGuid, authToken) if err != nil { fmt.Printf("===== Error getting recent messages: %v\n", err) } else { fmt.Println("===== Recent logs") for _, msg := range messages { fmt.Println(msg) } } fmt.Println("===== Streaming metrics") msgChan, errorChan := consumer.Stream(appGuid, authToken) go func() { for err := range errorChan { fmt.Fprintf(os.Stderr, "%v\n", err.Error()) } }() for msg := range msgChan { fmt.Printf("%v \n", msg) } }
const ( cfSetupTimeOut = 10 * time.Second cfPushTimeOut = 2 * time.Minute defaultMemoryLimit = "256MB" ) var _ = Describe("Logs", func() { It("gets through recent logs", func() { env := createLogEnvelope("I AM A BANANA!", "foo") helpers.EmitToMetron(env) tlsConfig := &tls.Config{InsecureSkipVerify: true} consumer := consumer.New(config.DopplerEndpoint, tlsConfig, nil) getRecentLogs := func() []*events.LogMessage { envelopes, err := consumer.RecentLogs("foo", "") Expect(err).NotTo(HaveOccurred()) return envelopes } Eventually(getRecentLogs).Should(ContainElement(env.LogMessage)) }) It("sends log messages for a specific app through the stream endpoint", func() { msgChan, errorChan := helpers.ConnectToStream("foo") helpers.EmitToMetron(createLogEnvelope("Stream message", "bar")) helpers.EmitToMetron(createLogEnvelope("Stream message", "foo")) receivedEnvelope, err := helpers.FindMatchingEnvelopeById("foo", msgChan) Expect(err).NotTo(HaveOccurred())