From: Adam Simpkins Date: Thu, 30 Nov 2017 01:35:11 +0000 (-0800) Subject: logging: don't clamp the log level to DFATAL in debug builds X-Git-Tag: v2017.12.04.00~19 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=commitdiff_plain;h=2fa201bf02cf80f9f2031b4bba70e3413da37efb logging: don't clamp the log level to DFATAL in debug builds Summary: Remove the logic that clamps the log level to DFATAL in debug builds. This behavior logically makes some sense, but results in subtle and potentially confusing behavior changes. It seems confusing that after calling `setLevel(LogLevel::MAX_LEVEL)` on a log category, calling `getLevel()` on that object would return `DFATAL` rather than `MAX_LEVEL`. We also weren't clamping the level to DFATAL consistently: `setLevel()` would clamp the value, but on construction the initial level was still set to MAX_LEVEL rather than DFATAL. This resulted in some issues when implementing `LoggerDB::getConfig()` since we could not consistently detect if a log category was using the default level settings. Rather than fix this inconsistency it seems better to simply remove this clamping behavior. This means that it is possible for users to disable DFATAL log messages even in debug builds if they really want to. Previously this was only allowed in release builds. This protection doesn't really seem all that valuable--presumably most developers won't really want to do this, and if they really do request this configuration it doesn't seem all that bad to honor it. Reviewed By: bolinfest, yfeldblum Differential Revision: D6200569 fbshipit-source-id: 83ef8e2e4d3b61bc5b105038cbe3132979e9ac67 --- diff --git a/folly/experimental/logging/LogCategory.cpp b/folly/experimental/logging/LogCategory.cpp index 66640df3..15f8a0dd 100644 --- a/folly/experimental/logging/LogCategory.cpp +++ b/folly/experimental/logging/LogCategory.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -155,16 +156,7 @@ void LogCategory::setLevelLocked(LogLevel level, bool inherit) { // // This makes sure that UNINITIALIZED is always less than any valid level // value, and that level values cannot conflict with our flag bits. - // - // In debug builds we clamp the maximum to DFATAL rather than MAX_LEVEL - // (FATAL), to ensure that fatal log messages can never be disabled. - constexpr LogLevel maxLogLevel = - kIsDebug ? LogLevel::DFATAL : LogLevel::MAX_LEVEL; - if (level > maxLogLevel) { - level = maxLogLevel; - } else if (level < LogLevel::MIN_LEVEL) { - level = LogLevel::MIN_LEVEL; - } + level = constexpr_clamp(level, LogLevel::MIN_LEVEL, LogLevel::MAX_LEVEL); // Make sure the inherit flag is always off for the root logger. if (!parent_) {