예제 #1
0
파일: agent.go 프로젝트: mattcui/bosh-agent
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)
}
예제 #2
0
파일: agent.go 프로젝트: EMC-CMD/bosh-agent
func main() {
	logger := newSignalableLogger(boshlog.NewLogger(boshlog.LevelDebug))

	defer logger.HandlePanic("Main")

	logger.Debug(mainLogTag, "Starting agent")

	fs := boshsys.NewOsFileSystem(logger)
	app := boshapp.New(logger, fs)

	err := app.Setup(os.Args)
	if err != nil {
		logger.Error(mainLogTag, "App setup %s", err.Error())
		os.Exit(1)
	}

	err = app.Run()
	if err != nil {
		logger.Error(mainLogTag, "App run %s", err.Error())
		os.Exit(1)
	}
}
예제 #3
0
	Describe("Warn", func() {
		It("logs the formatted message to Logger.err at the warn level", func() {
			logger := NewWriterLogger(LevelWarn, outBuf, errBuf)
			logger.Warn("TAG", "some %s info to log", "awesome")

			expectedContent := expectedLogFormat("TAG", "WARN - some awesome info to log")
			Expect(outBuf).ToNot(MatchRegexp(expectedContent))
			Expect(errBuf).To(MatchRegexp(expectedContent))
		})
	})

	Describe("Error", func() {
		It("logs the formatted message to Logger.err at the error level", func() {
			logger := NewWriterLogger(LevelError, outBuf, errBuf)
			logger.Error("TAG", "some %s info to log", "awesome")

			expectedContent := expectedLogFormat("TAG", "ERROR - some awesome info to log")
			Expect(outBuf).ToNot(MatchRegexp(expectedContent))
			Expect(errBuf).To(MatchRegexp(expectedContent))
		})
	})

	Describe("ErrorWithDetails", func() {
		It("logs the message to Logger.err at the error level with specially formatted arguments", func() {
			logger := NewWriterLogger(LevelError, outBuf, errBuf)

			logger.ErrorWithDetails("TAG", "some error to log", "awesome")

			expectedContent := expectedLogFormat("TAG", "ERROR - some error to log")
			Expect(outBuf).ToNot(MatchRegexp(expectedContent))
예제 #4
0
			Expect(outBuf).To(MatchRegexp(expectedContent))
			Expect(errBuf).ToNot(MatchRegexp(expectedContent))
		})

		It("does not block when its writer is blocked", func() {
			out := new(blockingWriter)
			err := new(blockingWriter)
			logger := NewAsyncWriterLogger(LevelDebug, out, err)

			out.Lock()
			err.Lock()
			ch := make(chan struct{}, 1)
			go func() {
				for i := 0; i < 10; i++ {
					logger.Debug("TAG", "Make sure we are not just buffering bytes: %s", strings.Repeat("A", 4096))
					logger.Error("TAG", "Make sure we are not just buffering bytes: %s", strings.Repeat("A", 4096))
				}
				ch <- struct{}{}
			}()
			Eventually(ch).Should(Receive())
			Expect(out.buf.Len()).To(Equal(0))
			Expect(err.buf.Len()).To(Equal(0))
		})

		It("copies queued log messages", func() {
			const s0 = "ABCDEFGHIJ"
			const s1 = "abcdefghij"

			out := new(blockingWriter)
			logger := NewAsyncWriterLogger(LevelDebug, out, errBuf)
예제 #5
0
			stdout, stderr := captureOutputs(func() {
				logger := NewLogger(LevelWarn)
				logger.Warn("TAG", "some %s info to log", "awesome")
			})

			expectedContent := expectedLogFormat("TAG", "WARN - some awesome info to log")
			Expect(stdout).ToNot(MatchRegexp(expectedContent))
			Expect(stderr).To(MatchRegexp(expectedContent))
		})
	})

	Describe("Error", func() {
		It("logs the formatted message to Logger.err at the error level", func() {
			stdout, stderr := captureOutputs(func() {
				logger := NewLogger(LevelError)
				logger.Error("TAG", "some %s info to log", "awesome")
			})

			expectedContent := expectedLogFormat("TAG", "ERROR - some awesome info to log")
			Expect(stdout).ToNot(MatchRegexp(expectedContent))
			Expect(stderr).To(MatchRegexp(expectedContent))
		})
	})

	Describe("ErrorWithDetails", func() {
		It("logs the message to Logger.err at the error level with specially formatted arguments", func() {
			stdout, stderr := captureOutputs(func() {
				logger := NewLogger(LevelError)
				logger.ErrorWithDetails("TAG", "some error to log", "awesome")
			})