diff options
author | Andy Getzendanner <durandal@google.com> | 2024-07-03 11:14:24 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2024-07-03 11:15:25 -0700 |
commit | 6e701508ea7505a8316f44a3ace6abcea585f287 (patch) | |
tree | 01c3164b91a051fadcb60a28737f09e7bf72def4 /absl/log/log_basic_test_impl.inc | |
parent | 0d9c2fc763dd766b868665a302ff4526748c4b36 (diff) |
Encode some additional metadata when writing protobuf-encoded logs.
PiperOrigin-RevId: 649138261
Change-Id: I8687eb7b06cc9e96779d1d3e98b44b4f643c95a8
Diffstat (limited to 'absl/log/log_basic_test_impl.inc')
-rw-r--r-- | absl/log/log_basic_test_impl.inc | 207 |
1 files changed, 126 insertions, 81 deletions
diff --git a/absl/log/log_basic_test_impl.inc b/absl/log/log_basic_test_impl.inc index 8083ff2c..7baf5e7b 100644 --- a/absl/log/log_basic_test_impl.inc +++ b/absl/log/log_basic_test_impl.inc @@ -53,6 +53,7 @@ using ::absl::log_internal::DeathTestValidateExpectations; using ::absl::log_internal::DiedOfFatal; using ::absl::log_internal::DiedOfQFatal; #endif +using ::absl::log_internal::InMatchWindow; using ::absl::log_internal::LoggingEnabledAt; using ::absl::log_internal::LogSeverity; using ::absl::log_internal::Prefix; @@ -62,7 +63,7 @@ using ::absl::log_internal::SourceLine; using ::absl::log_internal::Stacktrace; using ::absl::log_internal::TextMessage; using ::absl::log_internal::ThreadID; -using ::absl::log_internal::TimestampInMatchWindow; +using ::absl::log_internal::Timestamp; using ::absl::log_internal::Verbosity; using ::testing::AnyNumber; using ::testing::Eq; @@ -98,18 +99,20 @@ TEST_P(BasicLogTest, Info) { if (LoggingEnabledAt(absl::LogSeverity::kInfo)) { EXPECT_CALL( test_sink, - Send(AllOf(SourceFilename(Eq(__FILE__)), - SourceBasename(Eq("log_basic_test_impl.inc")), - SourceLine(Eq(log_line)), Prefix(IsTrue()), - LogSeverity(Eq(absl::LogSeverity::kInfo)), - TimestampInMatchWindow(), - ThreadID(Eq(absl::base_internal::GetTID())), - TextMessage(Eq("hello world")), - Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - literal: "hello world" - })pb")), - Stacktrace(IsEmpty())))); + Send(AllOf( + SourceFilename(Eq(__FILE__)), + SourceBasename(Eq("log_basic_test_impl.inc")), + SourceLine(Eq(log_line)), Prefix(IsTrue()), + LogSeverity(Eq(absl::LogSeverity::kInfo)), + Timestamp(InMatchWindow()), + ThreadID(Eq(absl::base_internal::GetTID())), + TextMessage(Eq("hello world")), + Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)), + ENCODED_MESSAGE(MatchesEvent( + Eq(__FILE__), Eq(log_line), InMatchWindow(), + Eq(logging::proto::INFO), Eq(absl::base_internal::GetTID()), + ElementsAre(EqualsProto(R"pb(literal: "hello world")pb")))), + Stacktrace(IsEmpty())))); } test_sink.StartCapturingLogs(); @@ -127,18 +130,20 @@ TEST_P(BasicLogTest, Warning) { if (LoggingEnabledAt(absl::LogSeverity::kWarning)) { EXPECT_CALL( test_sink, - Send(AllOf(SourceFilename(Eq(__FILE__)), - SourceBasename(Eq("log_basic_test_impl.inc")), - SourceLine(Eq(log_line)), Prefix(IsTrue()), - LogSeverity(Eq(absl::LogSeverity::kWarning)), - TimestampInMatchWindow(), - ThreadID(Eq(absl::base_internal::GetTID())), - TextMessage(Eq("hello world")), - Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - literal: "hello world" - })pb")), - Stacktrace(IsEmpty())))); + Send(AllOf( + SourceFilename(Eq(__FILE__)), + SourceBasename(Eq("log_basic_test_impl.inc")), + SourceLine(Eq(log_line)), Prefix(IsTrue()), + LogSeverity(Eq(absl::LogSeverity::kWarning)), + Timestamp(InMatchWindow()), + ThreadID(Eq(absl::base_internal::GetTID())), + TextMessage(Eq("hello world")), + Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)), + ENCODED_MESSAGE(MatchesEvent( + Eq(__FILE__), Eq(log_line), InMatchWindow(), + Eq(logging::proto::WARNING), Eq(absl::base_internal::GetTID()), + ElementsAre(EqualsProto(R"pb(literal: "hello world")pb")))), + Stacktrace(IsEmpty())))); } test_sink.StartCapturingLogs(); @@ -156,18 +161,20 @@ TEST_P(BasicLogTest, Error) { if (LoggingEnabledAt(absl::LogSeverity::kError)) { EXPECT_CALL( test_sink, - Send(AllOf(SourceFilename(Eq(__FILE__)), - SourceBasename(Eq("log_basic_test_impl.inc")), - SourceLine(Eq(log_line)), Prefix(IsTrue()), - LogSeverity(Eq(absl::LogSeverity::kError)), - TimestampInMatchWindow(), - ThreadID(Eq(absl::base_internal::GetTID())), - TextMessage(Eq("hello world")), - Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - literal: "hello world" - })pb")), - Stacktrace(IsEmpty())))); + Send(AllOf( + SourceFilename(Eq(__FILE__)), + SourceBasename(Eq("log_basic_test_impl.inc")), + SourceLine(Eq(log_line)), Prefix(IsTrue()), + LogSeverity(Eq(absl::LogSeverity::kError)), + Timestamp(InMatchWindow()), + ThreadID(Eq(absl::base_internal::GetTID())), + TextMessage(Eq("hello world")), + Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)), + ENCODED_MESSAGE(MatchesEvent( + Eq(__FILE__), Eq(log_line), InMatchWindow(), + Eq(logging::proto::ERROR), Eq(absl::base_internal::GetTID()), + ElementsAre(EqualsProto(R"pb(literal: "hello world")pb")))), + Stacktrace(IsEmpty())))); } test_sink.StartCapturingLogs(); @@ -211,12 +218,16 @@ TEST_P(BasicLogDeathTest, Fatal) { SourceBasename(Eq("log_basic_test_impl.inc")), SourceLine(Eq(log_line)), Prefix(IsTrue()), LogSeverity(Eq(absl::LogSeverity::kFatal)), - TimestampInMatchWindow(), + Timestamp(InMatchWindow()), ThreadID(Eq(absl::base_internal::GetTID())), TextMessage(Eq("hello world")), Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)), - ENCODED_MESSAGE(EqualsProto( - R"pb(value { literal: "hello world" })pb")), + ENCODED_MESSAGE(MatchesEvent( + Eq(__FILE__), Eq(log_line), InMatchWindow(), + Eq(logging::proto::FATAL), + Eq(absl::base_internal::GetTID()), + ElementsAre(EqualsProto( + R"pb(literal: "hello world")pb")))), Stacktrace(IsEmpty())))) .WillOnce(DeathTestExpectedLogging()); @@ -227,12 +238,16 @@ TEST_P(BasicLogDeathTest, Fatal) { SourceBasename(Eq("log_basic_test_impl.inc")), SourceLine(Eq(log_line)), Prefix(IsTrue()), LogSeverity(Eq(absl::LogSeverity::kFatal)), - TimestampInMatchWindow(), + Timestamp(InMatchWindow()), ThreadID(Eq(absl::base_internal::GetTID())), TextMessage(Eq("hello world")), Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)), - ENCODED_MESSAGE(EqualsProto( - R"pb(value { literal: "hello world" })pb")), + ENCODED_MESSAGE(MatchesEvent( + Eq(__FILE__), Eq(log_line), InMatchWindow(), + Eq(logging::proto::FATAL), + Eq(absl::base_internal::GetTID()), + ElementsAre(EqualsProto( + R"pb(literal: "hello world")pb")))), Stacktrace(Not(IsEmpty()))))) .WillOnce(DeathTestExpectedLogging()); } @@ -265,12 +280,16 @@ TEST_P(BasicLogDeathTest, QFatal) { SourceBasename(Eq("log_basic_test_impl.inc")), SourceLine(Eq(log_line)), Prefix(IsTrue()), LogSeverity(Eq(absl::LogSeverity::kFatal)), - TimestampInMatchWindow(), + Timestamp(InMatchWindow()), ThreadID(Eq(absl::base_internal::GetTID())), TextMessage(Eq("hello world")), Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)), - ENCODED_MESSAGE(EqualsProto( - R"pb(value { literal: "hello world" })pb")), + ENCODED_MESSAGE(MatchesEvent( + Eq(__FILE__), Eq(log_line), InMatchWindow(), + Eq(logging::proto::FATAL), + Eq(absl::base_internal::GetTID()), + ElementsAre(EqualsProto( + R"pb(literal: "hello world")pb")))), Stacktrace(IsEmpty())))) .WillOnce(DeathTestExpectedLogging()); } @@ -294,18 +313,20 @@ TEST_P(BasicLogTest, DFatal) { if (LoggingEnabledAt(absl::LogSeverity::kError)) { EXPECT_CALL( test_sink, - Send(AllOf(SourceFilename(Eq(__FILE__)), - SourceBasename(Eq("log_basic_test_impl.inc")), - SourceLine(Eq(log_line)), Prefix(IsTrue()), - LogSeverity(Eq(absl::LogSeverity::kError)), - TimestampInMatchWindow(), - ThreadID(Eq(absl::base_internal::GetTID())), - TextMessage(Eq("hello world")), - Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - literal: "hello world" - })pb")), - Stacktrace(IsEmpty())))); + Send(AllOf( + SourceFilename(Eq(__FILE__)), + SourceBasename(Eq("log_basic_test_impl.inc")), + SourceLine(Eq(log_line)), Prefix(IsTrue()), + LogSeverity(Eq(absl::LogSeverity::kError)), + Timestamp(InMatchWindow()), + ThreadID(Eq(absl::base_internal::GetTID())), + TextMessage(Eq("hello world")), + Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)), + ENCODED_MESSAGE(MatchesEvent( + Eq(__FILE__), Eq(log_line), InMatchWindow(), + Eq(logging::proto::ERROR), Eq(absl::base_internal::GetTID()), + ElementsAre(EqualsProto(R"pb(literal: "hello world")pb")))), + Stacktrace(IsEmpty())))); } test_sink.StartCapturingLogs(); @@ -339,12 +360,16 @@ TEST_P(BasicLogDeathTest, DFatal) { SourceBasename(Eq("log_basic_test_impl.inc")), SourceLine(Eq(log_line)), Prefix(IsTrue()), LogSeverity(Eq(absl::LogSeverity::kFatal)), - TimestampInMatchWindow(), + Timestamp(InMatchWindow()), ThreadID(Eq(absl::base_internal::GetTID())), TextMessage(Eq("hello world")), Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)), - ENCODED_MESSAGE(EqualsProto( - R"pb(value { literal: "hello world" })pb")), + ENCODED_MESSAGE(MatchesEvent( + Eq(__FILE__), Eq(log_line), InMatchWindow(), + Eq(logging::proto::FATAL), + Eq(absl::base_internal::GetTID()), + ElementsAre(EqualsProto( + R"pb(literal: "hello world")pb")))), Stacktrace(IsEmpty())))) .WillOnce(DeathTestExpectedLogging()); @@ -355,12 +380,16 @@ TEST_P(BasicLogDeathTest, DFatal) { SourceBasename(Eq("log_basic_test_impl.inc")), SourceLine(Eq(log_line)), Prefix(IsTrue()), LogSeverity(Eq(absl::LogSeverity::kFatal)), - TimestampInMatchWindow(), + Timestamp(InMatchWindow()), ThreadID(Eq(absl::base_internal::GetTID())), TextMessage(Eq("hello world")), Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)), - ENCODED_MESSAGE(EqualsProto( - R"pb(value { literal: "hello world" })pb")), + ENCODED_MESSAGE(MatchesEvent( + Eq(__FILE__), Eq(log_line), InMatchWindow(), + Eq(logging::proto::FATAL), + Eq(absl::base_internal::GetTID()), + ElementsAre(EqualsProto( + R"pb(literal: "hello world")pb")))), Stacktrace(Not(IsEmpty()))))) .WillOnce(DeathTestExpectedLogging()); } @@ -408,17 +437,25 @@ TEST_P(BasicLogTest, Level) { if (LoggingEnabledAt(severity)) { EXPECT_CALL( test_sink, - Send(AllOf(SourceFilename(Eq(__FILE__)), - SourceBasename(Eq("log_basic_test_impl.inc")), - SourceLine(Eq(log_line)), Prefix(IsTrue()), - LogSeverity(Eq(severity)), TimestampInMatchWindow(), - ThreadID(Eq(absl::base_internal::GetTID())), - TextMessage(Eq("hello world")), - Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - literal: "hello world" - })pb")), - Stacktrace(IsEmpty())))); + Send(AllOf( + SourceFilename(Eq(__FILE__)), + SourceBasename(Eq("log_basic_test_impl.inc")), + SourceLine(Eq(log_line)), Prefix(IsTrue()), + LogSeverity(Eq(severity)), Timestamp(InMatchWindow()), + ThreadID(Eq(absl::base_internal::GetTID())), + TextMessage(Eq("hello world")), + Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)), + ENCODED_MESSAGE(MatchesEvent( + Eq(__FILE__), Eq(log_line), InMatchWindow(), + Eq(severity == absl::LogSeverity::kInfo ? logging::proto::INFO + : severity == absl::LogSeverity::kWarning + ? logging::proto::WARNING + : severity == absl::LogSeverity::kError + ? logging::proto::ERROR + : 0), + Eq(absl::base_internal::GetTID()), + ElementsAre(EqualsProto(R"pb(literal: "hello world")pb")))), + Stacktrace(IsEmpty())))); } test_sink.StartCapturingLogs(); do_log(); @@ -455,12 +492,16 @@ TEST_P(BasicLogDeathTest, Level) { SourceBasename(Eq("log_basic_test_impl.inc")), SourceLine(Eq(log_line)), Prefix(IsTrue()), LogSeverity(Eq(absl::LogSeverity::kFatal)), - TimestampInMatchWindow(), + Timestamp(InMatchWindow()), ThreadID(Eq(absl::base_internal::GetTID())), TextMessage(Eq("hello world")), Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)), - ENCODED_MESSAGE(EqualsProto( - R"pb(value { literal: "hello world" })pb")), + ENCODED_MESSAGE(MatchesEvent( + Eq(__FILE__), Eq(log_line), InMatchWindow(), + Eq(logging::proto::FATAL), + Eq(absl::base_internal::GetTID()), + ElementsAre(EqualsProto( + R"pb(literal: "hello world")pb")))), Stacktrace(IsEmpty())))) .WillOnce(DeathTestExpectedLogging()); @@ -470,12 +511,16 @@ TEST_P(BasicLogDeathTest, Level) { SourceBasename(Eq("log_basic_test_impl.inc")), SourceLine(Eq(log_line)), Prefix(IsTrue()), LogSeverity(Eq(absl::LogSeverity::kFatal)), - TimestampInMatchWindow(), + Timestamp(InMatchWindow()), ThreadID(Eq(absl::base_internal::GetTID())), TextMessage(Eq("hello world")), Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)), - ENCODED_MESSAGE(EqualsProto( - R"pb(value { literal: "hello world" })pb")), + ENCODED_MESSAGE(MatchesEvent( + Eq(__FILE__), Eq(log_line), InMatchWindow(), + Eq(logging::proto::FATAL), + Eq(absl::base_internal::GetTID()), + ElementsAre(EqualsProto( + R"pb(literal: "hello world")pb")))), Stacktrace(Not(IsEmpty()))))) .WillOnce(DeathTestExpectedLogging()); } |