Fix SignalHandlerTest with ASAN
[folly.git] / folly / experimental / logging / LogLevel.h
index 0c751b15bd33af5f1390aa279c7a227fdde294da..605da0629174427ced23be7f8e8253f67ac6aa35 100644 (file)
@@ -56,15 +56,9 @@ enum class LogLevel : uint32_t {
   WARN = 3000,
   WARNING = 3000,
 
-  // Unfortunately Windows headers #define ERROR
-  // On Windows platforms we avoid defining ERROR.  However we make it
-  // available on other platforms, to make it easier to convert code from
-  // other log libraries that also use ERROR as their log level name (e.g.,
-  // glog).
+  // Unfortunately Windows headers #define ERROR, so we cannot use
+  // it as an enum value name.  We only provide ERR instead.
   ERR = 4000,
-#ifndef ERROR
-  ERROR = 4000,
-#endif
 
   CRITICAL = 5000,
 
@@ -87,12 +81,11 @@ enum class LogLevel : uint32_t {
  * adjusted log level values.
  */
 inline constexpr LogLevel operator+(LogLevel level, uint32_t value) {
-  auto newValue = static_cast<uint32_t>(level) + value;
   // Cap the result at LogLevel::MAX_LEVEL
-  if (newValue > static_cast<uint32_t>(LogLevel::MAX_LEVEL)) {
-    return LogLevel::MAX_LEVEL;
-  }
-  return static_cast<LogLevel>(newValue);
+  return ((static_cast<uint32_t>(level) + value) >
+          static_cast<uint32_t>(LogLevel::MAX_LEVEL))
+      ? LogLevel::MAX_LEVEL
+      : static_cast<LogLevel>(static_cast<uint32_t>(level) + value);
 }
 inline LogLevel& operator+=(LogLevel& level, uint32_t value) {
   level = level + value;
@@ -125,10 +118,7 @@ std::ostream& operator<<(std::ostream& os, LogLevel level);
  * Returns true if and only if a LogLevel is fatal.
  */
 inline constexpr bool isLogLevelFatal(LogLevel level) {
-  if (folly::kIsDebug) {
-    return level >= LogLevel::DFATAL;
-  } else {
-    return level >= LogLevel::FATAL;
-  }
-}
+  return folly::kIsDebug ? (level >= LogLevel::DFATAL)
+                         : (level >= LogLevel::FATAL);
 }
+} // namespace folly