Skip to content

Commit

Permalink
Replace use of logging::DEBUG_MODE with DCHECK_IS_ON().
Browse files Browse the repository at this point in the history
DEBUG_MODE was originally provided to allow code of the form:

  if (DEBUG_MODE) { ... }

rather than preprocessor conditional (i.e. #ifdef _DEBUG), while
still ensuring that the condition was static at compile-time, allowing
the affected code to be trivially optimized-out.

The function-like macro DCHECK_IS_ON(), added to simplify conditional
compilation of DCHECK-related code when DCHECK_ALWAYS_ON was added, can
now be used safely for both preprocessor and C++ conditionals in place of
DEBUG_MODE.

Review-Url: https://codereview.chromium.org/2731823002
Cr-Commit-Position: refs/heads/master@{#456519}
  • Loading branch information
wez authored and Commit bot committed Mar 13, 2017
1 parent 2fb4f2c commit 8ccfd32
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 16 deletions.
7 changes: 0 additions & 7 deletions base/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -747,13 +747,6 @@ DEFINE_CHECK_OP_IMPL(GT, > )

#endif // DCHECK_IS_ON()

// DEBUG_MODE is for runtime uses like
// if (DEBUG_MODE) foo.CheckThatFoo();
// We tie its state to DCHECK_IS_ON().
//
// For compile-time checks, #if DCHECK_IS_ON() can be used.
enum { DEBUG_MODE = DCHECK_IS_ON() };

#define DLOG(severity) \
LAZY_STREAM(LOG_STREAM(severity), DLOG_IS_ON(severity))

Expand Down
10 changes: 4 additions & 6 deletions base/logging_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,14 @@ class MockLogSource {

TEST_F(LoggingTest, BasicLogging) {
MockLogSource mock_log_source;
EXPECT_CALL(mock_log_source, Log()).Times(DEBUG_MODE ? 16 : 8).
WillRepeatedly(Return("log message"));
EXPECT_CALL(mock_log_source, Log())
.Times(DCHECK_IS_ON() ? 16 : 8)
.WillRepeatedly(Return("log message"));

SetMinLogLevel(LOG_INFO);

EXPECT_TRUE(LOG_IS_ON(INFO));
// As of g++-4.5, the first argument to EXPECT_EQ cannot be a
// constant expression.
const bool kIsDebugMode = (DEBUG_MODE != 0);
EXPECT_TRUE(kIsDebugMode == DLOG_IS_ON(INFO));
EXPECT_TRUE((DCHECK_IS_ON() != 0) == DLOG_IS_ON(INFO));
EXPECT_TRUE(VLOG_IS_ON(0));

LOG(INFO) << mock_log_source.Log();
Expand Down
2 changes: 1 addition & 1 deletion components/sync/base/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ bool VlogIsOnForLocation(const tracked_objects::Location& from_here,

#define DVLOG_LOC(from_here, verbose_level) \
LAZY_STREAM(VLOG_LOC_STREAM(from_here, verbose_level), \
::logging::DEBUG_MODE && \
DCHECK_IS_ON() && \
(VLOG_IS_ON(verbose_level) || \
::syncer::VlogIsOnForLocation(from_here, verbose_level)))

Expand Down
2 changes: 1 addition & 1 deletion components/sync/engine_impl/traffic_logger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void LogData(const T& data,
std::unique_ptr<base::DictionaryValue> (
*to_dictionary_value)(const T&, bool),
const std::string& description) {
if (::logging::DEBUG_MODE && VLOG_IS_ON(1)) {
if (DCHECK_IS_ON() && VLOG_IS_ON(1)) {
std::unique_ptr<base::DictionaryValue> value =
(*to_dictionary_value)(data, true /* include_specifics */);
std::string message;
Expand Down
2 changes: 1 addition & 1 deletion crypto/openssl_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void EnsureOpenSSLInit() {
}

void ClearOpenSSLERRStack(const tracked_objects::Location& location) {
if (logging::DEBUG_MODE && VLOG_IS_ON(1)) {
if (DCHECK_IS_ON() && VLOG_IS_ON(1)) {
uint32_t error_num = ERR_peek_error();
if (error_num == 0)
return;
Expand Down

0 comments on commit 8ccfd32

Please sign in to comment.