Example #1
0
func TestDebug(t *testing.T) {
	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(t, matcher.Match(stdout))
}
Example #2
0
func TestLogLevelError(t *testing.T) {
	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(t, string(stdout), "DEBUG")
	assert.NotContains(t, string(stdout), "INFO")
	assert.Contains(t, string(stderr), "ERROR")
}
Example #3
0
var _ = Describe("Logger", func() {
	It("info", func() {
		stdout, _ := captureOutputs(func() {
			logger := NewLogger(LevelInfo)
			logger.Info("TAG", "some %s info to log", "awesome")
		})

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

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

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

	It("debug with details", func() {
		stdout, _ := captureOutputs(func() {
			logger := NewLogger(LevelDebug)
			logger.DebugWithDetails("TAG", "some info to log", "awesome")
		})

		matcher, _ := regexp.Compile(expectedLogFormat("TAG", "DEBUG - some info to log"))
		Expect(matcher.Match(stdout)).To(BeTrue())
Example #4
0
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")
		})
	})
}