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) }
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) }
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]) } } }