X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=blobdiff_plain;f=folly%2Fexperimental%2Flogging%2FLogLevel.h;h=a3e0e34abf71c6cd8dbba0da8af076e9b916576d;hp=05c1603efcc72955134d0de177dd61d1161651e5;hb=7b116ffe3b116ffc3c2089ca0b864ca7ebb1d28c;hpb=ff607e1b1829884a32bbe80d7815ddfce9b6d3bf diff --git a/folly/experimental/logging/LogLevel.h b/folly/experimental/logging/LogLevel.h index 05c1603e..a3e0e34a 100644 --- a/folly/experimental/logging/LogLevel.h +++ b/folly/experimental/logging/LogLevel.h @@ -18,7 +18,9 @@ #include #include #include +#include +#include #include namespace folly { @@ -60,12 +62,15 @@ enum class LogLevel : uint32_t { // other log libraries that also use ERROR as their log level name (e.g., // glog). ERR = 4000, -#ifndef ERROR - ERROR = 4000, -#endif CRITICAL = 5000, + // DFATAL log messages crash the program on debug builds. + DFATAL = 0x7ffffffe, + // FATAL log messages always abort the program. + // This level is equivalent to MAX_LEVEL. + FATAL = 0x7fffffff, + // The most significant bit is used by LogCategory to store a flag value, // so the maximum value has that bit cleared. // @@ -78,19 +83,18 @@ enum class LogLevel : uint32_t { * Support adding and subtracting integers from LogLevels, to create slightly * adjusted log level values. */ -inline LogLevel operator+(LogLevel level, uint32_t value) { - auto newValue = static_cast(level) + value; +inline constexpr LogLevel operator+(LogLevel level, uint32_t value) { // Cap the result at LogLevel::MAX_LEVEL - if (newValue > static_cast(LogLevel::MAX_LEVEL)) { - return LogLevel::MAX_LEVEL; - } - return static_cast(newValue); + return ((static_cast(level) + value) > + static_cast(LogLevel::MAX_LEVEL)) + ? LogLevel::MAX_LEVEL + : static_cast(static_cast(level) + value); } inline LogLevel& operator+=(LogLevel& level, uint32_t value) { level = level + value; return level; } -inline LogLevel operator-(LogLevel level, uint32_t value) { +inline constexpr LogLevel operator-(LogLevel level, uint32_t value) { return static_cast(static_cast(level) - value); } inline LogLevel& operator-=(LogLevel& level, uint32_t value) { @@ -112,4 +116,12 @@ std::string logLevelToString(LogLevel level); * Print a LogLevel in a human readable format. */ std::ostream& operator<<(std::ostream& os, LogLevel level); + +/** + * Returns true if and only if a LogLevel is fatal. + */ +inline constexpr bool isLogLevelFatal(LogLevel level) { + return folly::kIsDebug ? (level >= LogLevel::DFATAL) + : (level >= LogLevel::FATAL); +} }