Skip to content
This repository was archived by the owner on Jun 30, 2025. It is now read-only.

Commit 0b3d4cb

Browse files
authored
Merge pull request #651 from xkszltl/initapi
Expose `IsGoogleLoggingInitialized()` in public API.
2 parents d5c04ee + 81e0d61 commit 0b3d4cb

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

src/glog/logging.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,9 @@ GOOGLE_GLOG_DLL_DECL void InitGoogleLogging(const char* argv0,
594594
void* prefix_callback_data = NULL);
595595
#endif
596596

597+
// Check if google's logging library has been initialized.
598+
GOOGLE_GLOG_DLL_DECL bool IsGoogleLoggingInitialized();
599+
597600
// Shutdown google's logging library.
598601
GOOGLE_GLOG_DLL_DECL void ShutdownGoogleLogging();
599602

src/logging_custom_prefix_unittest.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,15 @@ int main(int argc, char **argv) {
221221
LogWithLevels(0, 0, 0, 0); // simulate "before global c-tors"
222222
const string early_stderr = GetCapturedTestStderr();
223223

224+
EXPECT_FALSE(IsGoogleLoggingInitialized());
225+
224226
// Setting a custom prefix generator (it will use the default format so that
225227
// the golden outputs can be reused):
226228
string prefix_attacher_data = "good data";
227229
InitGoogleLogging(argv[0], &PrefixAttacher, static_cast<void*>(&prefix_attacher_data));
228230

231+
EXPECT_TRUE(IsGoogleLoggingInitialized());
232+
229233
RunSpecifiedBenchmarks();
230234

231235
FLAGS_logtostderr = true;
@@ -992,8 +996,10 @@ static void TestCustomLoggerDeletionOnShutdown() {
992996
base::SetLogger(GLOG_INFO,
993997
new RecordDeletionLogger(&custom_logger_deleted,
994998
base::GetLogger(GLOG_INFO)));
999+
EXPECT_TRUE(IsGoogleLoggingInitialized());
9951000
ShutdownGoogleLogging();
9961001
EXPECT_TRUE(custom_logger_deleted);
1002+
EXPECT_FALSE(IsGoogleLoggingInitialized());
9971003
}
9981004

9991005
_START_GOOGLE_NAMESPACE_

src/logging_unittest.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,12 @@ int main(int argc, char **argv) {
197197
LogWithLevels(0, 0, 0, 0); // simulate "before global c-tors"
198198
const string early_stderr = GetCapturedTestStderr();
199199

200+
EXPECT_FALSE(IsGoogleLoggingInitialized());
201+
200202
InitGoogleLogging(argv[0]);
201203

204+
EXPECT_TRUE(IsGoogleLoggingInitialized());
205+
202206
RunSpecifiedBenchmarks();
203207

204208
FLAGS_logtostderr = true;
@@ -965,8 +969,10 @@ static void TestCustomLoggerDeletionOnShutdown() {
965969
base::SetLogger(GLOG_INFO,
966970
new RecordDeletionLogger(&custom_logger_deleted,
967971
base::GetLogger(GLOG_INFO)));
972+
EXPECT_TRUE(IsGoogleLoggingInitialized());
968973
ShutdownGoogleLogging();
969974
EXPECT_TRUE(custom_logger_deleted);
975+
EXPECT_FALSE(IsGoogleLoggingInitialized());
970976
}
971977

972978
_START_GOOGLE_NAMESPACE_

src/utilities.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ _START_GOOGLE_NAMESPACE_
6262

6363
static const char* g_program_invocation_short_name = NULL;
6464

65+
bool IsGoogleLoggingInitialized() {
66+
return g_program_invocation_short_name != NULL;
67+
}
68+
6569
_END_GOOGLE_NAMESPACE_
6670

6771
// The following APIs are all internal.
@@ -176,10 +180,6 @@ const char* ProgramInvocationShortName() {
176180
}
177181
}
178182

179-
bool IsGoogleLoggingInitialized() {
180-
return g_program_invocation_short_name != NULL;
181-
}
182-
183183
#ifdef OS_WINDOWS
184184
struct timeval {
185185
long tv_sec, tv_usec;

src/utilities.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,6 @@ namespace glog_internal_namespace_ {
163163

164164
const char* ProgramInvocationShortName();
165165

166-
bool IsGoogleLoggingInitialized();
167-
168166
int64 CycleClock_Now();
169167

170168
int64 UsecToCycles(int64 usec);

0 commit comments

Comments
 (0)