Beispiel #1
0
func TestOutput(t *testing.T) {
	logger, out := createTestLogger(log.Debug)

	logger.Emergency(testMessage)
	logtest.AssertContains(t, out, "1985-06-17 18:30:59.012 EMERGENCY "+testMessage)

	logger.Alert(testMessage)
	logtest.AssertContains(t, out, "1985-06-17 18:30:59.012 ALERT "+testMessage)

	logger.Critical(testMessage)
	logtest.AssertContains(t, out, "1985-06-17 18:30:59.012 CRITICAL "+testMessage)

	logger.Error(testMessage)
	logtest.AssertContains(t, out, "1985-06-17 18:30:59.012 ERROR "+testMessage)

	logger.Warning(testMessage)
	logtest.AssertContains(t, out, "1985-06-17 18:30:59.012 WARNING "+testMessage)

	logger.Notice(testMessage)
	logtest.AssertContains(t, out, "1985-06-17 18:30:59.012 NOTICE "+testMessage)

	logger.Info(testMessage)
	logtest.AssertContains(t, out, "1985-06-17 18:30:59.012 INFO "+testMessage)

	logger.Debug(testMessage)
	logtest.AssertContains(t, out, "1985-06-17 18:30:59.012 DEBUG "+testMessage)

	logger.Log(log.Info, testMessage)
	logtest.AssertContains(t, out, "1985-06-17 18:30:59.012 INFO "+testMessage)

	logtest.AssertLineCount(t, out, 9)
}
Beispiel #2
0
func TestFormatedLogging(t *testing.T) {
	logger, out := createTestLogger(log.Info)

	logger.Infof("%d %s", 1, "test")
	logtest.AssertContains(t, out, "1 test")

	logtest.AssertLineCount(t, out, 1)
}
Beispiel #3
0
func TestGetFromFlags(t *testing.T) {
	logger := getLogger("info", "none")

	logger.Debug(logtest.Messages[log.Debug])
	logtest.AssertNotContain(t, testStream, logtest.Messages[log.Debug])

	logger.Info(logtest.Messages[log.Info])
	logtest.AssertContains(t, testStream, logtest.Messages[log.Info])
	logtest.AssertLineCount(t, testStream, 1)

	logger = getLogger("info", "error")

	logger.Info(logtest.Messages[log.Info])
	logtest.AssertNotContain(t, testStream, logtest.Messages[log.Info])

	logger.Error(logtest.Messages[log.Error])
	logtest.AssertContains(t, testStream, logtest.Messages[log.Error])
	logtest.AssertLineCount(t, testStream, 2)
}
Beispiel #4
0
func TestConcurrentLogging(t *testing.T) {
	logger, out := createTestLogger(log.Info)
	done := make(chan bool)

	logger.Info("Test")
	go func() {
		logger.Info("Test")
		done <- true
	}()
	logger.Info("Test")
	<-done

	logtest.AssertLineCount(t, out, 3)
}
Beispiel #5
0
func TestBufferedLogging(t *testing.T) {
	logger, out := createLogger(log.Info, log.Error)

	logger.Debug(logtest.Messages[log.Debug])
	logtest.AssertNotContain(t, out, logtest.Messages[log.Debug])

	logger.Info(logtest.Messages[log.Info])
	logtest.AssertNotContain(t, out, logtest.Messages[log.Info])

	logger.Error(logtest.Messages[log.Error])
	logtest.AssertNotContain(t, out, logtest.Messages[log.Debug])
	logtest.AssertContains(t, out, logtest.Messages[log.Info])
	logtest.AssertContains(t, out, logtest.Messages[log.Error])

	logger.Warning(logtest.Messages[log.Warning])
	logtest.AssertContains(t, out, logtest.Messages[log.Warning])

	logger.Alert(logtest.Messages[log.Alert])
	logtest.AssertContains(t, out, logtest.Messages[log.Alert])

	logtest.AssertLineCount(t, out, 4)
}