Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose IsGoogleLoggingInitialized() in public API. #651

Merged
merged 1 commit into from
May 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/glog/logging.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,9 @@ GOOGLE_GLOG_DLL_DECL void InitGoogleLogging(const char* argv0,
void* prefix_callback_data = NULL);
#endif

// Check if google's logging library has been initialized.
GOOGLE_GLOG_DLL_DECL bool IsGoogleLoggingInitialized();

// Shutdown google's logging library.
GOOGLE_GLOG_DLL_DECL void ShutdownGoogleLogging();

Expand Down
6 changes: 6 additions & 0 deletions src/logging_custom_prefix_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(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<void*>(&prefix_attacher_data));

EXPECT_TRUE(IsGoogleLoggingInitialized());

RunSpecifiedBenchmarks();

FLAGS_logtostderr = true;
Expand Down Expand Up @@ -992,8 +996,10 @@ static void TestCustomLoggerDeletionOnShutdown() {
base::SetLogger(GLOG_INFO,
new RecordDeletionLogger(&custom_logger_deleted,
base::GetLogger(GLOG_INFO)));
EXPECT_TRUE(IsGoogleLoggingInitialized());
ShutdownGoogleLogging();
EXPECT_TRUE(custom_logger_deleted);
EXPECT_FALSE(IsGoogleLoggingInitialized());
}

_START_GOOGLE_NAMESPACE_
Expand Down
6 changes: 6 additions & 0 deletions src/logging_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(IsGoogleLoggingInitialized());

InitGoogleLogging(argv[0]);

EXPECT_TRUE(IsGoogleLoggingInitialized());

RunSpecifiedBenchmarks();

FLAGS_logtostderr = true;
Expand Down Expand Up @@ -965,8 +969,10 @@ static void TestCustomLoggerDeletionOnShutdown() {
base::SetLogger(GLOG_INFO,
new RecordDeletionLogger(&custom_logger_deleted,
base::GetLogger(GLOG_INFO)));
EXPECT_TRUE(IsGoogleLoggingInitialized());
ShutdownGoogleLogging();
EXPECT_TRUE(custom_logger_deleted);
EXPECT_FALSE(IsGoogleLoggingInitialized());
}

_START_GOOGLE_NAMESPACE_
Expand Down
8 changes: 4 additions & 4 deletions src/utilities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ _START_GOOGLE_NAMESPACE_

static const char* g_program_invocation_short_name = NULL;

bool IsGoogleLoggingInitialized() {
return g_program_invocation_short_name != NULL;
}

_END_GOOGLE_NAMESPACE_

// The following APIs are all internal.
Expand Down Expand Up @@ -176,10 +180,6 @@ const char* ProgramInvocationShortName() {
}
}

bool IsGoogleLoggingInitialized() {
return g_program_invocation_short_name != NULL;
}

#ifdef OS_WINDOWS
struct timeval {
long tv_sec, tv_usec;
Expand Down
2 changes: 0 additions & 2 deletions src/utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@ namespace glog_internal_namespace_ {

const char* ProgramInvocationShortName();

bool IsGoogleLoggingInitialized();

int64 CycleClock_Now();

int64 UsecToCycles(int64 usec);
Expand Down