diff --git a/src/glog/logging.h.in b/src/glog/logging.h.in index 421f1e026..0b1466b05 100644 --- a/src/glog/logging.h.in +++ b/src/glog/logging.h.in @@ -594,6 +594,8 @@ GOOGLE_GLOG_DLL_DECL void InitGoogleLogging(const char* argv0, void* prefix_callback_data = NULL); #endif +GOOGLE_GLOG_DLL_DECL bool IsGoogleLoggingInitialized(); + // Shutdown google's logging library. GOOGLE_GLOG_DLL_DECL void ShutdownGoogleLogging(); diff --git a/src/logging.cc b/src/logging.cc index 71de91df9..e8d175c68 100644 --- a/src/logging.cc +++ b/src/logging.cc @@ -2568,6 +2568,10 @@ void InitGoogleLogging(const char* argv0, } #endif +bool IsGoogleLoggingInitialized() { + return g_program_invocation_short_name != NULL; +} + void ShutdownGoogleLogging() { glog_internal_namespace_::ShutdownGoogleLoggingUtilities(); LogDestination::DeleteLogDestinations(); diff --git a/src/logging_custom_prefix_unittest.cc b/src/logging_custom_prefix_unittest.cc index c9fb5b819..b7f20f001 100644 --- a/src/logging_custom_prefix_unittest.cc +++ b/src/logging_custom_prefix_unittest.cc @@ -221,11 +221,15 @@ int main(int argc, char **argv) { LogWithLevels(0, 0, 0, 0); // simulate "before global c-tors" const string early_stderr = GetCapturedTestStderr(); + EXPECT_FALSE(::google::IsGoogleLoggingInitialized()); + // Setting a custom prefix generator (it will use the default format so that // the golden outputs can be reused): string prefix_attacher_data = "good data"; InitGoogleLogging(argv[0], &PrefixAttacher, static_cast(&prefix_attacher_data)); + EXPECT_TRUE(::google::IsGoogleLoggingInitialized()); + RunSpecifiedBenchmarks(); FLAGS_logtostderr = true; @@ -992,8 +996,10 @@ static void TestCustomLoggerDeletionOnShutdown() { base::SetLogger(GLOG_INFO, new RecordDeletionLogger(&custom_logger_deleted, base::GetLogger(GLOG_INFO))); + EXPECT_TRUE(::google::IsGoogleLoggingInitialized()); ShutdownGoogleLogging(); EXPECT_TRUE(custom_logger_deleted); + EXPECT_FALSE(::google::IsGoogleLoggingInitialized()); } _START_GOOGLE_NAMESPACE_ diff --git a/src/logging_unittest.cc b/src/logging_unittest.cc index edc7d35d7..395603a45 100644 --- a/src/logging_unittest.cc +++ b/src/logging_unittest.cc @@ -197,8 +197,12 @@ int main(int argc, char **argv) { LogWithLevels(0, 0, 0, 0); // simulate "before global c-tors" const string early_stderr = GetCapturedTestStderr(); + EXPECT_FALSE(::google::IsGoogleLoggingInitialized()); + InitGoogleLogging(argv[0]); + EXPECT_TRUE(::google::IsGoogleLoggingInitialized()); + RunSpecifiedBenchmarks(); FLAGS_logtostderr = true; @@ -965,8 +969,10 @@ static void TestCustomLoggerDeletionOnShutdown() { base::SetLogger(GLOG_INFO, new RecordDeletionLogger(&custom_logger_deleted, base::GetLogger(GLOG_INFO))); + EXPECT_TRUE(::google::IsGoogleLoggingInitialized()); ShutdownGoogleLogging(); EXPECT_TRUE(custom_logger_deleted); + EXPECT_FALSE(::google::IsGoogleLoggingInitialized()); } _START_GOOGLE_NAMESPACE_ diff --git a/src/utilities.cc b/src/utilities.cc index 6b9a69e63..b4d425aae 100644 --- a/src/utilities.cc +++ b/src/utilities.cc @@ -60,7 +60,7 @@ using std::string; _START_GOOGLE_NAMESPACE_ -static const char* g_program_invocation_short_name = NULL; +const char* g_program_invocation_short_name = NULL; _END_GOOGLE_NAMESPACE_ @@ -176,10 +176,6 @@ const char* ProgramInvocationShortName() { } } -bool IsGoogleLoggingInitialized() { - return g_program_invocation_short_name != NULL; -} - #ifdef OS_WINDOWS struct timeval { long tv_sec, tv_usec; diff --git a/src/utilities.h b/src/utilities.h index e4115ad45..f8cb2c71f 100644 --- a/src/utilities.h +++ b/src/utilities.h @@ -149,6 +149,8 @@ _START_GOOGLE_NAMESPACE_ +extern const char* g_program_invocation_short_name; + namespace glog_internal_namespace_ { #ifdef HAVE___ATTRIBUTE__ @@ -163,8 +165,6 @@ namespace glog_internal_namespace_ { const char* ProgramInvocationShortName(); -bool IsGoogleLoggingInitialized(); - int64 CycleClock_Now(); int64 UsecToCycles(int64 usec);