예제 #1
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)
	}
}
예제 #2
0
})

var _ = Describe("Logger", func() {
	var (
		outBuf *bytes.Buffer
		errBuf *bytes.Buffer
	)
	BeforeEach(func() {
		outBuf = new(bytes.Buffer)
		errBuf = new(bytes.Buffer)
	})

	Describe("Debug", func() {
		It("logs the formatted message to Logger.out at the debug level", func() {
			logger := NewWriterLogger(LevelDebug, outBuf, errBuf)
			logger.Debug("TAG", "some %s info to log", "awesome")

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

	Describe("DebugWithDetails", func() {
		It("logs the message to Logger.out at the debug level with specially formatted arguments", func() {
			logger := NewWriterLogger(LevelDebug, outBuf, errBuf)
			logger.DebugWithDetails("TAG", "some info to log", "awesome")
			expectedContent := expectedLogFormat("TAG", "DEBUG - some info to log")
			Expect(outBuf).To(MatchRegexp(expectedContent))
			Expect(errBuf).ToNot(MatchRegexp(expectedContent))
예제 #3
0
}

var _ = Describe("Logger", func() {
	var (
		outBuf = new(bytes.Buffer)
		errBuf = new(bytes.Buffer)
	)
	BeforeEach(func() {
		outBuf.Reset()
		errBuf.Reset()
	})

	Describe("Async Logger", func() {
		It("logs the formatted message to Logger.out at the debug level", func() {
			logger := NewAsyncWriterLogger(LevelDebug, outBuf, errBuf)
			logger.Debug("TAG", "some %s info to log", "awesome")
			logger.Flush()

			expectedContent := expectedLogFormat("TAG", "DEBUG - some awesome info to log")
			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)
예제 #4
0
		_, err := Levelify("unknown")
		Expect(err).To(HaveOccurred())
		Expect(err.Error()).To(Equal("Unknown LogLevel string 'unknown', expected one of [DEBUG, INFO, WARN, ERROR, NONE]"))

		_, err = Levelify("")
		Expect(err).To(HaveOccurred())
		Expect(err.Error()).To(Equal("Unknown LogLevel string '', expected one of [DEBUG, INFO, WARN, ERROR, NONE]"))
	})
})

var _ = Describe("Logger", func() {
	Describe("Debug", func() {
		It("logs the formatted message to Logger.out at the debug level", func() {
			stdout, stderr := captureOutputs(func() {
				logger := NewLogger(LevelDebug)
				logger.Debug("TAG", "some %s info to log", "awesome")
			})

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

	Describe("DebugWithDetails", func() {
		It("logs the message to Logger.out at the debug level with specially formatted arguments", func() {
			stdout, stderr := captureOutputs(func() {
				logger := NewLogger(LevelDebug)
				logger.DebugWithDetails("TAG", "some info to log", "awesome")
			})