string logLevelToString(LogLevel level) {
if (level == LogLevel::UNINITIALIZED) {
- return "LogLevel::UNINITIALIZED";
+ return "UNINITIALIZED";
} else if (level == LogLevel::NONE) {
- return "LogLevel::NONE";
+ return "NONE";
} else if (level == LogLevel::DEBUG) {
- return "LogLevel::DEBUG";
+ return "DEBUG";
} else if (level == LogLevel::INFO) {
- return "LogLevel::INFO";
+ return "INFO";
} else if (level == LogLevel::WARN) {
- return "LogLevel::WARN";
+ return "WARN";
} else if (level == LogLevel::ERR) {
- return "LogLevel::ERR";
+ return "ERR";
} else if (level == LogLevel::CRITICAL) {
- return "LogLevel::CRITICAL";
+ return "CRITICAL";
} else if (level == LogLevel::DFATAL) {
- return "LogLevel::DFATAL";
+ return "DFATAL";
} else if (level == LogLevel::FATAL) {
- return "LogLevel::FATAL";
+ return "FATAL";
}
if (static_cast<uint32_t>(level) <= static_cast<uint32_t>(LogLevel::DBG0) &&
static_cast<uint32_t>(level) > static_cast<uint32_t>(LogLevel::DEBUG)) {
auto num =
static_cast<uint32_t>(LogLevel::DBG0) - static_cast<uint32_t>(level);
- return folly::to<string>("LogLevel::DBG", num);
+ return folly::to<string>("DBG", num);
}
return folly::to<string>("LogLevel(", static_cast<uint32_t>(level), ")");
}
}
TEST(LogLevel, toString) {
- EXPECT_EQ(
- "LogLevel::UNINITIALIZED", logLevelToString(LogLevel::UNINITIALIZED));
- EXPECT_EQ("LogLevel::NONE", logLevelToString(LogLevel::NONE));
- EXPECT_EQ("LogLevel::INFO", logLevelToString(LogLevel::INFO));
- EXPECT_EQ("LogLevel::WARN", logLevelToString(LogLevel::WARN));
- EXPECT_EQ("LogLevel::WARN", logLevelToString(LogLevel::WARNING));
- EXPECT_EQ("LogLevel::DEBUG", logLevelToString(LogLevel::DEBUG));
- EXPECT_EQ("LogLevel::ERR", logLevelToString(LogLevel::ERR));
- EXPECT_EQ("LogLevel::CRITICAL", logLevelToString(LogLevel::CRITICAL));
- EXPECT_EQ("LogLevel::DFATAL", logLevelToString(LogLevel::DFATAL));
- EXPECT_EQ("LogLevel::FATAL", logLevelToString(LogLevel::FATAL));
- EXPECT_EQ("LogLevel::FATAL", logLevelToString(LogLevel::MAX_LEVEL));
-
- EXPECT_EQ("LogLevel::DBG0", logLevelToString(LogLevel::DBG0));
- EXPECT_EQ("LogLevel::DBG2", logLevelToString(LogLevel::DBG2));
- EXPECT_EQ("LogLevel::DBG5", logLevelToString(LogLevel::DBG5));
- EXPECT_EQ("LogLevel::DBG9", logLevelToString(LogLevel::DBG9));
- EXPECT_EQ("LogLevel::DBG97", logLevelToString(static_cast<LogLevel>(903)));
- EXPECT_EQ("LogLevel::DBG64", logLevelToString(LogLevel::DBG4 - 60));
+ EXPECT_EQ("UNINITIALIZED", logLevelToString(LogLevel::UNINITIALIZED));
+ EXPECT_EQ("NONE", logLevelToString(LogLevel::NONE));
+ EXPECT_EQ("INFO", logLevelToString(LogLevel::INFO));
+ EXPECT_EQ("WARN", logLevelToString(LogLevel::WARN));
+ EXPECT_EQ("WARN", logLevelToString(LogLevel::WARNING));
+ EXPECT_EQ("DEBUG", logLevelToString(LogLevel::DEBUG));
+ EXPECT_EQ("ERR", logLevelToString(LogLevel::ERR));
+ EXPECT_EQ("CRITICAL", logLevelToString(LogLevel::CRITICAL));
+ EXPECT_EQ("DFATAL", logLevelToString(LogLevel::DFATAL));
+ EXPECT_EQ("FATAL", logLevelToString(LogLevel::FATAL));
+ EXPECT_EQ("FATAL", logLevelToString(LogLevel::MAX_LEVEL));
+
+ EXPECT_EQ("DBG0", logLevelToString(LogLevel::DBG0));
+ EXPECT_EQ("DBG2", logLevelToString(LogLevel::DBG2));
+ EXPECT_EQ("DBG5", logLevelToString(LogLevel::DBG5));
+ EXPECT_EQ("DBG9", logLevelToString(LogLevel::DBG9));
+ EXPECT_EQ("DBG97", logLevelToString(static_cast<LogLevel>(903)));
+ EXPECT_EQ("DBG64", logLevelToString(LogLevel::DBG4 - 60));
EXPECT_EQ("LogLevel(1234)", logLevelToString(static_cast<LogLevel>(1234)));
}
handler.handleMessage(msg, handlerCategory);
ASSERT_EQ(1, writer->getMessages().size());
EXPECT_EQ(
- "LogLevel::DBG8::log_cat::handler_cat::src/test.cpp::1234::hello world",
+ "DBG8::log_cat::handler_cat::src/test.cpp::1234::hello world",
writer->getMessages()[0]);
}
auto& messages = writer->getMessages();
ASSERT_EQ(2, messages.size());
EXPECT_EQ(
- "LogLevel::WARN::log_cat::handler_cat::src/test.cpp::1234::beware",
- messages.at(0));
+ "WARN::log_cat::handler_cat::src/test.cpp::1234::beware", messages.at(0));
EXPECT_EQ(
- "LogLevel::ERR::log_cat::handler_cat::src/test.cpp::1234::whoops",
- messages.at(1));
+ "ERR::log_cat::handler_cat::src/test.cpp::1234::whoops", messages.at(1));
messages.clear();
handler.setLevel(LogLevel::DBG2);
ASSERT_EQ(3, messages.size());
EXPECT_EQ(
- "LogLevel::DBG1::log_cat::handler_cat::src/test.cpp::1234::here",
- messages.at(0));
+ "DBG1::log_cat::handler_cat::src/test.cpp::1234::here", messages.at(0));
EXPECT_EQ(
- "LogLevel::DBG2::log_cat::handler_cat::src/test.cpp::1234::and here",
+ "DBG2::log_cat::handler_cat::src/test.cpp::1234::and here",
messages.at(1));
EXPECT_EQ(
- "LogLevel::ERR::log_cat::handler_cat::src/test.cpp::1234::oh noes",
- messages.at(2));
+ "ERR::log_cat::handler_cat::src/test.cpp::1234::oh noes", messages.at(2));
messages.clear();
}