コード例 #1
0
ファイル: golog_test.go プロジェクト: shazow/log
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)
}
コード例 #2
0
ファイル: golog_test.go プロジェクト: shazow/log
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)
}
コード例 #3
0
ファイル: stdlog_test.go プロジェクト: shazow/log
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)
}
コード例 #4
0
ファイル: buflog_test.go プロジェクト: shazow/log
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)
}
コード例 #5
0
ファイル: golog_test.go プロジェクト: shazow/log
func testLogThreshold(t *testing.T, level log.Level, isLoggedList map[log.Level]bool) {
	logger, out := createTestLogger(level)

	logger.Emergency(logtest.Messages[log.Emergency])
	logger.Alert(logtest.Messages[log.Alert])
	logger.Critical(logtest.Messages[log.Critical])
	logger.Error(logtest.Messages[log.Error])
	logger.Warning(logtest.Messages[log.Warning])
	logger.Notice(logtest.Messages[log.Notice])
	logger.Info(logtest.Messages[log.Info])
	logger.Debug(logtest.Messages[log.Debug])

	for level, isLogged := range isLoggedList {
		if isLogged {
			logtest.AssertContains(t, out, logtest.Messages[level])
		} else {
			logtest.AssertNotContain(t, out, logtest.Messages[level])
		}
	}
}