コード例 #1
0
ファイル: logger_test.go プロジェクト: reneedv/bosh
func TestErrorWithDetails(t *testing.T) {
	_, stderr := captureOutputs(func() {
		logger := NewLogger(LEVEL_ERROR)
		logger.ErrorWithDetails("TAG", "some error to log", "awesome")
	})

	matcher, _ := regexp.Compile(expectedLogFormat("TAG", "ERROR - some error to log"))
	assert.True(t, matcher.Match(stderr))

	assert.Contains(t, string(stderr), "\n********************\nawesome\n********************")
}
コード例 #2
0
ファイル: logger_test.go プロジェクト: Bosh-for-Cpi/bosh-2605
	})

	It("error", func() {
		_, stderr := captureOutputs(func() {
			logger := NewLogger(LevelError)
			logger.Error("TAG", "some %s info to log", "awesome")
		})

		matcher, _ := regexp.Compile(expectedLogFormat("TAG", "ERROR - some awesome info to log"))
		Expect(matcher.Match(stderr)).To(BeTrue())
	})

	It("error with details", func() {
		_, stderr := captureOutputs(func() {
			logger := NewLogger(LevelError)
			logger.ErrorWithDetails("TAG", "some error to log", "awesome")
		})

		matcher, _ := regexp.Compile(expectedLogFormat("TAG", "ERROR - some error to log"))
		Expect(matcher.Match(stderr)).To(BeTrue())

		assert.Contains(GinkgoT(), string(stderr), "\n********************\nawesome\n********************")
	})

	It("log level debug", func() {
		stdout, stderr := captureOutputs(func() {
			logger := NewLogger(LevelDebug)
			logger.Debug("DEBUG", "some debug log")
			logger.Info("INFO", "some info log")
			logger.Error("ERROR", "some error log")
		})
コード例 #3
0
ファイル: logger_test.go プロジェクト: nkuacac/bosh
func init() {
	Describe("Testing with Ginkgo", func() {
		It("info", func() {
			stdout, _ := captureOutputs(func() {
				logger := NewLogger(LEVEL_INFO)
				logger.Info("TAG", "some %s info to log", "awesome")
			})

			matcher, _ := regexp.Compile(expectedLogFormat("TAG", "INFO - some awesome info to log"))
			assert.True(GinkgoT(), matcher.Match(stdout))
		})
		It("debug", func() {

			stdout, _ := captureOutputs(func() {
				logger := NewLogger(LEVEL_DEBUG)
				logger.Debug("TAG", "some %s info to log", "awesome")
			})

			matcher, _ := regexp.Compile(expectedLogFormat("TAG", "DEBUG - some awesome info to log"))
			assert.True(GinkgoT(), matcher.Match(stdout))
		})
		It("debug with details", func() {

			stdout, _ := captureOutputs(func() {
				logger := NewLogger(LEVEL_DEBUG)
				logger.DebugWithDetails("TAG", "some info to log", "awesome")
			})

			matcher, _ := regexp.Compile(expectedLogFormat("TAG", "DEBUG - some info to log"))
			assert.True(GinkgoT(), matcher.Match(stdout))

			assert.Contains(GinkgoT(), string(stdout), "\n********************\nawesome\n********************")
		})
		It("error", func() {

			_, stderr := captureOutputs(func() {
				logger := NewLogger(LEVEL_ERROR)
				logger.Error("TAG", "some %s info to log", "awesome")
			})

			matcher, _ := regexp.Compile(expectedLogFormat("TAG", "ERROR - some awesome info to log"))
			assert.True(GinkgoT(), matcher.Match(stderr))
		})
		It("error with details", func() {

			_, stderr := captureOutputs(func() {
				logger := NewLogger(LEVEL_ERROR)
				logger.ErrorWithDetails("TAG", "some error to log", "awesome")
			})

			matcher, _ := regexp.Compile(expectedLogFormat("TAG", "ERROR - some error to log"))
			assert.True(GinkgoT(), matcher.Match(stderr))

			assert.Contains(GinkgoT(), string(stderr), "\n********************\nawesome\n********************")
		})
		It("log level debug", func() {

			stdout, stderr := captureOutputs(func() {
				logger := NewLogger(LEVEL_DEBUG)
				logger.Debug("DEBUG", "some debug log")
				logger.Info("INFO", "some info log")
				logger.Error("ERROR", "some error log")
			})

			assert.Contains(GinkgoT(), string(stdout), "DEBUG")
			assert.Contains(GinkgoT(), string(stdout), "INFO")
			assert.Contains(GinkgoT(), string(stderr), "ERROR")
		})
		It("log level info", func() {

			stdout, stderr := captureOutputs(func() {
				logger := NewLogger(LEVEL_INFO)
				logger.Debug("DEBUG", "some debug log")
				logger.Info("INFO", "some info log")
				logger.Error("ERROR", "some error log")
			})

			assert.NotContains(GinkgoT(), string(stdout), "DEBUG")
			assert.Contains(GinkgoT(), string(stdout), "INFO")
			assert.Contains(GinkgoT(), string(stderr), "ERROR")
		})
		It("log level error", func() {

			stdout, stderr := captureOutputs(func() {
				logger := NewLogger(LEVEL_ERROR)
				logger.Debug("DEBUG", "some debug log")
				logger.Info("INFO", "some info log")
				logger.Error("ERROR", "some error log")
			})

			assert.NotContains(GinkgoT(), string(stdout), "DEBUG")
			assert.NotContains(GinkgoT(), string(stdout), "INFO")
			assert.Contains(GinkgoT(), string(stderr), "ERROR")
		})
	})
}