Exemplo n.º 1
0
func main() {
	asyncLog := boshlog.NewAsyncWriterLogger(boshlog.LevelDebug, os.Stdout, os.Stderr)
	logger := newSignalableLogger(asyncLog)

	exitCode := 0
	if err := startAgent(logger); err != nil {
		logger.Error(mainLogTag, "Agent exited with error: %s", err)
		exitCode = 1
	}
	logger.FlushTimeout(time.Minute)
	os.Exit(exitCode)
}
Exemplo n.º 2
0
			out.Lock()
			for i := 0; i < 10; i++ {
				logger.Debug("TAG", "Queued log message")
			}
			Expect(out.buf.Len()).To(Equal(0))
			out.Unlock()
			Eventually(out.buf.Len).ShouldNot(Equal(0))
		})

		It("flushes with a timeout", func() {
			out := new(blockingWriter)
			logger := NewAsyncWriterLogger(LevelDebug, out, errBuf)
			logger.Debug("TAG", "something")

			out.Lock()
			Expect(logger.FlushTimeout(time.Millisecond * 10)).ToNot(Succeed())

			out.Unlock()
			Expect(logger.FlushTimeout(time.Millisecond * 10)).To(Succeed())
			Expect(strings.TrimSpace(out.buf.String())).To(HaveSuffix("something"))
		})

		It("flush doesn't block writes", func() {
			const (
				MessageCount  = 10
				WriteInterval = 10 * time.Millisecond
				FlushInterval = 10 * WriteInterval
			)

			out := &intervalWriter{dur: WriteInterval}
			logger := NewAsyncWriterLogger(LevelDebug, out, errBuf)