func main() { log.Printf("Agent starting, use CTL-C to quit\n") defer log.Printf("Agent stopped\n") var debug bool flag.BoolVar(&debug, "debug", false, "Enable debug logging.") flag.Parse() if debug { emitter.DefaultEmitter = emitter.NewLoggingEmitter() } stopChan := make(chan struct{}) go func() { err := agent.Run(stopChan) if err != nil { log.Fatalf("failed to run agent: %v", err) } }() killChan := make(chan os.Signal, 2) signal.Notify(killChan, syscall.SIGINT, syscall.SIGTERM) for { select { case <-RegisterGoRoutineDumpSignalChannel(): DumpGoRoutine() case <-killChan: close(stopChan) return } } }
"github.com/cloudfoundry-incubator/dropsonde/events" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "log" ) var _ = Describe("LoggingEmitter", func() { Describe("Emit", func() { Context("with valid data", func() { It("logs emitted messages", func() { logWriter := new(bytes.Buffer) log.SetOutput(logWriter) emitter := emitter.NewLoggingEmitter() envelope := &events.Envelope{ Origin: events.NewOrigin("job-name", 42), EventType: events.Envelope_Heartbeat.Enum(), Heartbeat: events.NewHeartbeat(1, 2, 3), } data, err := proto.Marshal(envelope) Expect(err).ToNot(HaveOccurred()) err = emitter.Emit(data) Expect(err).ToNot(HaveOccurred()) loggedText := string(logWriter.Bytes()) expectedText := proto.CompactTextString(envelope)