-
Notifications
You must be signed in to change notification settings - Fork 455
Avoid conditional compilation on whether tracing is enabled #914
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
Merged
vector-of-bool
merged 2 commits into
mongodb:master
from
vector-of-bool:log-macro-cleanup
Dec 15, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,9 +39,7 @@ | |
static bson_once_t once = BSON_ONCE_INIT; | ||
static bson_mutex_t gLogMutex; | ||
static mongoc_log_func_t gLogFunc = mongoc_log_default_handler; | ||
#ifdef MONGOC_TRACE | ||
static bool gLogTrace = true; | ||
#endif | ||
static bool gLogTrace = MONGOC_TRACE_ENABLED; | ||
static void *gLogData; | ||
|
||
static BSON_ONCE_FUN (_mongoc_ensure_mutex_once) | ||
|
@@ -62,6 +60,26 @@ mongoc_log_set_handler (mongoc_log_func_t log_func, void *user_data) | |
bson_mutex_unlock (&gLogMutex); | ||
} | ||
|
||
bool | ||
_mongoc_log_trace_is_enabled (void) | ||
{ | ||
return gLogTrace && MONGOC_TRACE_ENABLED; | ||
} | ||
|
||
void | ||
mongoc_log_trace_enable (void) | ||
{ | ||
/* Enable trace logging if-and-only-if tracing is enabled at configure-time, | ||
* otherwise tracing remains disabled. | ||
*/ | ||
gLogTrace = MONGOC_TRACE_ENABLED; | ||
} | ||
|
||
void | ||
mongoc_log_trace_disable (void) | ||
{ | ||
gLogTrace = false; | ||
} | ||
|
||
/* just for testing */ | ||
void | ||
|
@@ -85,10 +103,8 @@ mongoc_log (mongoc_log_level_t log_level, | |
bson_once (&once, &_mongoc_ensure_mutex_once); | ||
|
||
stop_logging = !gLogFunc; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this check be combined into _mongoc_log_trace_is_enabled()? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unsure. I left the logic as close to the original as possible. |
||
#ifdef MONGOC_TRACE | ||
stop_logging = | ||
stop_logging || (log_level == MONGOC_LOG_LEVEL_TRACE && !gLogTrace); | ||
#endif | ||
stop_logging = stop_logging || (log_level == MONGOC_LOG_LEVEL_TRACE && | ||
!_mongoc_log_trace_is_enabled ()); | ||
if (stop_logging) { | ||
return; | ||
} | ||
|
@@ -203,44 +219,16 @@ mongoc_log_default_handler (mongoc_log_level_t log_level, | |
message); | ||
} | ||
|
||
bool | ||
_mongoc_log_trace_is_enabled (void) | ||
{ | ||
#ifdef MONGOC_TRACE | ||
return gLogTrace; | ||
#else | ||
return false; | ||
#endif | ||
} | ||
|
||
void | ||
mongoc_log_trace_enable (void) | ||
{ | ||
#ifdef MONGOC_TRACE | ||
gLogTrace = true; | ||
#endif | ||
} | ||
|
||
void | ||
mongoc_log_trace_disable (void) | ||
{ | ||
#ifdef MONGOC_TRACE | ||
gLogTrace = false; | ||
#endif | ||
} | ||
|
||
void | ||
mongoc_log_trace_bytes (const char *domain, const uint8_t *_b, size_t _l) | ||
{ | ||
bson_string_t *str, *astr; | ||
int32_t _i; | ||
uint8_t _v; | ||
|
||
#ifdef MONGOC_TRACE | ||
if (!gLogTrace) { | ||
if (!_mongoc_log_trace_is_enabled ()) { | ||
return; | ||
} | ||
#endif | ||
|
||
str = bson_string_new (NULL); | ||
astr = bson_string_new (NULL); | ||
|
@@ -291,11 +279,9 @@ mongoc_log_trace_iovec (const char *domain, | |
size_t _l = 0; | ||
uint8_t _v; | ||
|
||
#ifdef MONGOC_TRACE | ||
if (!gLogTrace) { | ||
if (!_mongoc_log_trace_is_enabled ()) { | ||
return; | ||
} | ||
#endif | ||
|
||
for (_i = 0; _i < _iovcnt; _i++) { | ||
_l += _iov[_i].iov_len; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This unexpectedly broke PHPC's build system (autotools). I've reported CDRIVER-4247 to request a more portable approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved in #917.