func BenchmarkSeelogTextNegative(b *testing.B) { stream := &blackholeStream{} logger, err := log.LoggerFromWriterWithMinLevelAndFormat(stream, log.ErrorLvl, "%Time %Level %Msg") if err != nil { b.Fatal(err) } b.ResetTimer() b.RunParallel(func(pb *testing.PB) { defer logger.Flush() for pb.Next() { logger.Info("The quick brown fox jumps over the lazy dog") } }) if stream.WriteCount() != uint64(0) { b.Fatalf("Log write count") } }
func testLoggerWithContext(t *testing.T, testCase TestCase) { // create seelog logger that outputs to buffer var out bytes.Buffer seelogger, err := seelog.LoggerFromWriterWithMinLevelAndFormat(&out, seelog.TraceLvl, testCase.LogFormat) assert.Nil(t, err) // call method under test logger := withContext(seelogger, testCase.Context) // exercise logger switch testCase.Level { case seelog.ErrorLvl: if len(testCase.Params) > 0 { logger.Errorf(testCase.Message, testCase.Params...) } else { logger.Error(testCase.Message) } case seelog.InfoLvl: if len(testCase.Params) > 0 { logger.Infof(testCase.Message, testCase.Params...) } else { logger.Info(testCase.Message) } case seelog.DebugLvl: if len(testCase.Params) > 0 { logger.Debugf(testCase.Message, testCase.Params...) } else { logger.Debug(testCase.Message) } default: assert.Fail(t, "Unexpected log level", testCase.Level) } logger.Flush() // check result assert.Equal(t, testCase.Output, out.String()) }