logging: shorten output of logLevelToString()
authorAdam Simpkins <simpkins@fb.com>
Wed, 21 Jun 2017 20:23:28 +0000 (13:23 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Wed, 21 Jun 2017 20:36:58 +0000 (13:36 -0700)
Summary:
Remove the "LogLevel::" prefix from the logLevelToString() output.

This makes the output shorter and easier to read, and makes it simpler to write
LogFormatter implementations that want a short human-readable level
description.  Callers can always add a "LogLevel::" prefix on their own if
desired.

Reviewed By: wez

Differential Revision: D5288601

fbshipit-source-id: 046579ebdda76842d5a44c33d68941d73dd81162

folly/experimental/logging/LogLevel.cpp
folly/experimental/logging/test/LogLevelTest.cpp
folly/experimental/logging/test/StandardLogHandlerTest.cpp

index c16eadb..c70ad6b 100644 (file)
@@ -87,30 +87,30 @@ LogLevel stringToLogLevel(StringPiece name) {
 
 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), ")");
 }
index 3415f97..d580f61 100644 (file)
@@ -81,25 +81,24 @@ TEST(LogLevel, fromString) {
 }
 
 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)));
 }
index 6a1f78d..9de6ce4 100644 (file)
@@ -83,7 +83,7 @@ TEST(StandardLogHandler, simple) {
   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]);
 }
 
@@ -109,11 +109,9 @@ TEST(StandardLogHandler, levelCheck) {
   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);
@@ -125,13 +123,11 @@ TEST(StandardLogHandler, levelCheck) {
 
   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();
 }