Made logging not look up --enable-dcheck from command line
Made --enable-dcheck a parameter to InitLogging() and fixed up all
callsites.
BUG=62736
TEST=Manual
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=70782
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=70920
Review URL: http://codereview.chromium.org/6070006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70977 0039d316-1c4b-4281-b951-d872f2087c98
CrOS-Libchrome-Original-Commit: 7c10f7553bf4da999f954e501fc2908e10dd3bcf
diff --git a/base/logging.cc b/base/logging.cc
index 5b6e2c1..d66f01b 100644
--- a/base/logging.cc
+++ b/base/logging.cc
@@ -64,7 +64,7 @@
namespace logging {
-bool g_enable_dcheck = false;
+DcheckState g_dcheck_state = DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS;
VlogInfo* g_vlog_info = NULL;
const char* const log_severity_names[LOG_NUM_SEVERITIES] = {
@@ -353,10 +353,10 @@
bool BaseInitLoggingImpl(const PathChar* new_log_file,
LoggingDestination logging_dest,
LogLockingState lock_log,
- OldFileDeletionState delete_old) {
+ OldFileDeletionState delete_old,
+ DcheckState dcheck_state) {
CommandLine* command_line = CommandLine::ForCurrentProcess();
- g_enable_dcheck =
- command_line->HasSwitch(switches::kEnableDCHECK);
+ g_dcheck_state = dcheck_state;
delete g_vlog_info;
g_vlog_info = NULL;
// Don't bother initializing g_vlog_info unless we use one of the
diff --git a/base/logging.h b/base/logging.h
index a097568..662deae 100644
--- a/base/logging.h
+++ b/base/logging.h
@@ -165,6 +165,11 @@
// Defaults to APPEND_TO_OLD_LOG_FILE.
enum OldFileDeletionState { DELETE_OLD_LOG_FILE, APPEND_TO_OLD_LOG_FILE };
+enum DcheckState {
+ DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS,
+ ENABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS
+};
+
// TODO(avi): do we want to do a unification of character types here?
#if defined(OS_WIN)
typedef wchar_t PathChar;
@@ -188,7 +193,8 @@
bool BaseInitLoggingImpl(const PathChar* log_file,
LoggingDestination logging_dest,
LogLockingState lock_log,
- OldFileDeletionState delete_old);
+ OldFileDeletionState delete_old,
+ DcheckState dcheck_state);
// Sets the log file name and other global logging state. Calling this function
// is recommended, and is normally done at the beginning of application init.
@@ -203,8 +209,10 @@
inline bool InitLogging(const PathChar* log_file,
LoggingDestination logging_dest,
LogLockingState lock_log,
- OldFileDeletionState delete_old) {
- return BaseInitLoggingImpl(log_file, logging_dest, lock_log, delete_old);
+ OldFileDeletionState delete_old,
+ DcheckState dcheck_state) {
+ return BaseInitLoggingImpl(log_file, logging_dest, lock_log,
+ delete_old, dcheck_state);
}
// Sets the log level. Anything at or above this level will be written to the
@@ -600,10 +608,11 @@
COMPACT_GOOGLE_LOG_EX_ERROR_REPORT(ClassName , ##__VA_ARGS__)
#define COMPACT_GOOGLE_LOG_DCHECK COMPACT_GOOGLE_LOG_ERROR_REPORT
const LogSeverity LOG_DCHECK = LOG_ERROR_REPORT;
-// This is set to true in InitLogging when we want to enable the
-// DCHECKs in release.
-extern bool g_enable_dcheck;
-#define DCHECK_IS_ON() (::logging::g_enable_dcheck && LOG_IS_ON(DCHECK))
+extern DcheckState g_dcheck_state;
+#define DCHECK_IS_ON() \
+ ((::logging::g_dcheck_state == \
+ ::logging::ENABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS) && \
+ LOG_IS_ON(DCHECK))
#else // defined(NDEBUG)
diff --git a/base/logging_unittest.cc b/base/logging_unittest.cc
index 4b7fdbc..bb6e3d1 100644
--- a/base/logging_unittest.cc
+++ b/base/logging_unittest.cc
@@ -197,7 +197,7 @@
#if !defined(LOGGING_IS_OFFICIAL_BUILD) && defined(NDEBUG)
// Unofficial release build.
- logging::g_enable_dcheck = false;
+ g_dcheck_state = DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS;
DCHECK(mock_log_source.Log()) << mock_log_source.Log();
DPCHECK(mock_log_source.Log()) << mock_log_source.Log();
DCHECK_EQ(0, 0) << mock_log_source.Log();
@@ -213,13 +213,13 @@
EXPECT_FALSE(DLOG_IS_ON(DCHECK));
#elif defined(NDEBUG)
// Unofficial release build.
- logging::g_enable_dcheck = true;
- logging::SetLogReportHandler(&LogSink);
+ g_dcheck_state = ENABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS;
+ SetLogReportHandler(&LogSink);
EXPECT_TRUE(DCHECK_IS_ON());
EXPECT_FALSE(DLOG_IS_ON(DCHECK));
#else
// Unofficial debug build.
- logging::SetLogAssertHandler(&LogSink);
+ SetLogAssertHandler(&LogSink);
EXPECT_TRUE(DCHECK_IS_ON());
EXPECT_TRUE(DLOG_IS_ON(DCHECK));
#endif // defined(LOGGING_IS_OFFICIAL_BUILD)
diff --git a/base/test/test_suite.cc b/base/test/test_suite.cc
index aa23f04..5f8a616 100644
--- a/base/test/test_suite.cc
+++ b/base/test/test_suite.cc
@@ -175,10 +175,12 @@
FilePath exe;
PathService::Get(base::FILE_EXE, &exe);
FilePath log_filename = exe.ReplaceExtension(FILE_PATH_LITERAL("log"));
- logging::InitLogging(log_filename.value().c_str(),
- logging::LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG,
- logging::LOCK_LOG_FILE,
- logging::DELETE_OLD_LOG_FILE);
+ logging::InitLogging(
+ log_filename.value().c_str(),
+ logging::LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG,
+ logging::LOCK_LOG_FILE,
+ logging::DELETE_OLD_LOG_FILE,
+ logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS);
// We want process and thread IDs because we may have multiple processes.
// Note: temporarily enabled timestamps in an effort to catch bug 6361.
logging::SetLogItems(true, true, true, true);