diff --git a/third-party/folly/src/folly/logging/test/CustomLogFormatterTest.cpp b/third-party/folly/src/folly/logging/test/CustomLogFormatterTest.cpp index a4f6209866d92..b12a5fab42a30 100644 --- a/third-party/folly/src/folly/logging/test/CustomLogFormatterTest.cpp +++ b/third-party/folly/src/folly/logging/test/CustomLogFormatterTest.cpp @@ -18,6 +18,8 @@ #include +#include + #include #include #include @@ -28,6 +30,7 @@ FOLLY_GNU_DISABLE_WARNING("-Wdeprecated-declarations") +using namespace fmt::literals; using namespace folly; namespace { @@ -178,21 +181,17 @@ TEST(CustomLogFormatter, fileNoExt) { } TEST(CustomLogFormatter, multiline) { - auto tid = getOSThreadID(); - std::map formatMap{ - {"tid", folly::to(tid)}}; - // Log a multi-line message - auto expected = folly::svformat( - "V0417 13:45:56.123456 {tid:>5s} rodent.cpp:777] Eeek, a mouse!\n" - "V0417 13:45:56.123456 {tid:>5s} rodent.cpp:777] . .\n" - "V0417 13:45:56.123456 {tid:>5s} rodent.cpp:777] ( ).( )\n" - "V0417 13:45:56.123456 {tid:>5s} rodent.cpp:777] (o o) .-._.'\n" - "V0417 13:45:56.123456 {tid:>5s} rodent.cpp:777] ( - )\n" - "V0417 13:45:56.123456 {tid:>5s} rodent.cpp:777] mm mm\n" - "V0417 13:45:56.123456 {tid:>5s} rodent.cpp:777] \n" - "V0417 13:45:56.123456 {tid:>5s} rodent.cpp:777] =============\n", - formatMap); + auto expected = fmt::format( + "V0417 13:45:56.123456 {tid:>5} rodent.cpp:777] Eeek, a mouse!\n" + "V0417 13:45:56.123456 {tid:>5} rodent.cpp:777] . .\n" + "V0417 13:45:56.123456 {tid:>5} rodent.cpp:777] ( ).( )\n" + "V0417 13:45:56.123456 {tid:>5} rodent.cpp:777] (o o) .-._.'\n" + "V0417 13:45:56.123456 {tid:>5} rodent.cpp:777] ( - )\n" + "V0417 13:45:56.123456 {tid:>5} rodent.cpp:777] mm mm\n" + "V0417 13:45:56.123456 {tid:>5} rodent.cpp:777] \n" + "V0417 13:45:56.123456 {tid:>5} rodent.cpp:777] =============\n", + "tid"_a = getOSThreadID()); EXPECT_EQ( expected, formatMsg( @@ -238,15 +237,11 @@ TEST(CustomLogFormatter, multiline) { } TEST(CustomLogFormatter, singleNewline) { - auto tid = getOSThreadID(); - std::map formatMap{ - {"tid", folly::to(tid)}}; - // Logging a single newline is basically two empty strings. - auto expected = folly::svformat( - "V0417 13:45:56.123456 {tid:>5s} foo.txt:123] \n" - "V0417 13:45:56.123456 {tid:>5s} foo.txt:123] \n", - formatMap); + auto expected = fmt::format( + "V0417 13:45:56.123456 {tid:>5} foo.txt:123] \n" + "V0417 13:45:56.123456 {tid:>5} foo.txt:123] \n", + "tid"_a = getOSThreadID()); EXPECT_EQ( expected, formatMsg( @@ -265,9 +260,9 @@ TEST(CustomLogFormatter, coloring) { { // Logging a DBG9 message should log in grey color (\033[1;30m) and should // call reset color at the end of the message (\033[0m) - auto expected = folly::svformat( - "\033[1;30mV0417 13:45:56.123456 {tid:>5s} foo.txt:123] DBG9\033[0m\n", - formatMap); + auto expected = fmt::format( + "\033[1;30mV0417 13:45:56.123456 {tid:>5} foo.txt:123] DBG9\033[0m\n", + "tid"_a = getOSThreadID()); EXPECT_EQ( expected, formatMsg( @@ -281,8 +276,9 @@ TEST(CustomLogFormatter, coloring) { } { // Logging an INFO message when coloring enabled is displayed as regular // message. i.e. no color or reset sequence - auto expected = folly::svformat( - "I0417 13:45:56.123456 {tid:>5s} foo.txt:123] INFO\n", formatMap); + auto expected = fmt::format( + "I0417 13:45:56.123456 {tid:>5} foo.txt:123] INFO\n", + "tid"_a = getOSThreadID()); EXPECT_EQ( expected, formatMsg( @@ -296,9 +292,9 @@ TEST(CustomLogFormatter, coloring) { } { // Logging a WARN message should log in yellow color (\033[33m) and should // call reset color at the end of the message (\033[0m) - auto expected = folly::svformat( - "\033[33mW0417 13:45:56.123456 {tid:>5s} foo.txt:123] WARN\033[0m\n", - formatMap); + auto expected = fmt::format( + "\033[33mW0417 13:45:56.123456 {tid:>5} foo.txt:123] WARN\033[0m\n", + "tid"_a = getOSThreadID()); EXPECT_EQ( expected, formatMsg( @@ -312,9 +308,9 @@ TEST(CustomLogFormatter, coloring) { } { // Logging a ERR message should log in red color (\033[31m) and should // call reset color at the end of the message (\033[0m) - auto expected = folly::svformat( - "\033[31mE0417 13:45:56.123456 {tid:>5s} foo.txt:123] ERR\033[0m\n", - formatMap); + auto expected = fmt::format( + "\033[31mE0417 13:45:56.123456 {tid:>5} foo.txt:123] ERR\033[0m\n", + "tid"_a = getOSThreadID()); EXPECT_EQ( expected, formatMsg( @@ -328,10 +324,10 @@ TEST(CustomLogFormatter, coloring) { } { // Logging a CRITICAL message should log bold in red background (\033[1;41m) // and should call reset color at the end of the message (\033[0m) - auto expected = folly::svformat( - "\033[1;41mC0417 13:45:56.123456 {tid:>5s} foo.txt:123] " + auto expected = fmt::format( + "\033[1;41mC0417 13:45:56.123456 {tid:>5} foo.txt:123] " "CRITICAL\033[0m\n", - formatMap); + "tid"_a = getOSThreadID()); EXPECT_EQ( expected, formatMsg( @@ -345,10 +341,10 @@ TEST(CustomLogFormatter, coloring) { } { // Logging a FATAL message should log bold in red background (\033[1;41m) // and should call reset color at the end of the message (\033[0m) - auto expected = folly::svformat( - "\033[1;41mF0417 13:45:56.123456 {tid:>5s} foo.txt:123] " + auto expected = fmt::format( + "\033[1;41mF0417 13:45:56.123456 {tid:>5} foo.txt:123] " "FATAL\033[0m\n", - formatMap); + "tid"_a = getOSThreadID()); EXPECT_EQ( expected, formatMsg( diff --git a/third-party/folly/src/folly/logging/test/GlogFormatterTest.cpp b/third-party/folly/src/folly/logging/test/GlogFormatterTest.cpp index a7e4bb5dfebd4..4551fe1dccbc6 100644 --- a/third-party/folly/src/folly/logging/test/GlogFormatterTest.cpp +++ b/third-party/folly/src/folly/logging/test/GlogFormatterTest.cpp @@ -16,6 +16,8 @@ #include +#include + #include #include #include @@ -28,6 +30,7 @@ FOLLY_GNU_DISABLE_WARNING("-Wdeprecated-declarations") +using namespace fmt::literals; using namespace folly; namespace { @@ -166,20 +169,19 @@ TEST(GlogFormatter, filename) { TEST(GlogFormatter, multiline) { auto tid = getOSThreadID(); - std::map formatMap{ - {"tid", folly::to(tid)}}; // Log a multi-line message - auto expected = folly::svformat( - "V0417 13:45:56.123456 {tid:>5s} rodent.cpp:777] Eeek, a mouse!\n" - "V0417 13:45:56.123456 {tid:>5s} rodent.cpp:777] . .\n" - "V0417 13:45:56.123456 {tid:>5s} rodent.cpp:777] ( ).( )\n" - "V0417 13:45:56.123456 {tid:>5s} rodent.cpp:777] (o o) .-._.'\n" - "V0417 13:45:56.123456 {tid:>5s} rodent.cpp:777] ( - )\n" - "V0417 13:45:56.123456 {tid:>5s} rodent.cpp:777] mm mm\n" - "V0417 13:45:56.123456 {tid:>5s} rodent.cpp:777] \n" - "V0417 13:45:56.123456 {tid:>5s} rodent.cpp:777] =============\n", - formatMap); + auto expected = fmt::format( + "V0417 13:45:56.123456 {tid:>5} rodent.cpp:777] Eeek, a mouse!\n" + "V0417 13:45:56.123456 {tid:>5} rodent.cpp:777] . .\n" + "V0417 13:45:56.123456 {tid:>5} rodent.cpp:777] ( ).( )\n" + "V0417 13:45:56.123456 {tid:>5} rodent.cpp:777] (o o) .-._.'\n" + "V0417 13:45:56.123456 {tid:>5} rodent.cpp:777] ( - )\n" + "V0417 13:45:56.123456 {tid:>5} rodent.cpp:777] mm mm\n" + "V0417 13:45:56.123456 {tid:>5} rodent.cpp:777] \n" + "V0417 13:45:56.123456 {tid:>5} rodent.cpp:777] =============\n", + + "tid"_a = tid); EXPECT_EQ( expected, formatMsg( @@ -199,14 +201,13 @@ TEST(GlogFormatter, multiline) { TEST(GlogFormatter, singleNewline) { auto tid = getOSThreadID(); - std::map formatMap{ - {"tid", folly::to(tid)}}; // Logging a single newline is basically two empty strings. - auto expected = folly::svformat( - "V0417 13:45:56.123456 {tid:>5s} foo.txt:123] \n" - "V0417 13:45:56.123456 {tid:>5s} foo.txt:123] \n", - formatMap); + auto expected = fmt::format( + "V0417 13:45:56.123456 {tid:>5} foo.txt:123] \n" + "V0417 13:45:56.123456 {tid:>5} foo.txt:123] \n", + + "tid"_a = tid); EXPECT_EQ( expected, formatMsg(LogLevel::DBG9, "\n", "foo.txt", 123, "testFunction"));