Skip to content

Commit 1761c7a

Browse files
authored
CDRIVER-4800 return from trace functions if no logger (#1712)
* add macro to stop logs * wrap macro in if/else block
1 parent ce52097 commit 1761c7a

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/libmongoc/src/mongoc/mongoc-log-private.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,12 @@ mongoc_log_trace_bytes (const char *domain, const uint8_t *_b, size_t _l);
3434
void
3535
mongoc_log_trace_iovec (const char *domain, const mongoc_iovec_t *_iov, size_t _iovcnt);
3636

37+
#define STOP_LOGGING_CHECK \
38+
if (1) { \
39+
if (!gLogFunc || !_mongoc_log_trace_is_enabled ()) { \
40+
return; \
41+
} \
42+
} else \
43+
(void) 0
44+
3745
#endif /* MONGOC_LOG_PRIVATE_H */

src/libmongoc/src/mongoc/mongoc-log.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,7 @@ mongoc_log_default_handler (mongoc_log_level_t log_level, const char *log_domain
217217
void
218218
mongoc_log_trace_bytes (const char *domain, const uint8_t *_b, size_t _l)
219219
{
220-
if (!_mongoc_log_trace_is_enabled ()) {
221-
return;
222-
}
220+
STOP_LOGGING_CHECK;
223221

224222
bson_string_t *const str = bson_string_new (NULL);
225223
bson_string_t *const astr = bson_string_new (NULL);
@@ -269,9 +267,7 @@ mongoc_log_trace_iovec (const char *domain, const mongoc_iovec_t *_iov, size_t _
269267
size_t _l = 0;
270268
uint8_t _v;
271269

272-
if (!_mongoc_log_trace_is_enabled ()) {
273-
return;
274-
}
270+
STOP_LOGGING_CHECK;
275271

276272
for (_i = 0; _i < _iovcnt; _i++) {
277273
_l += _iov[_i].iov_len;

0 commit comments

Comments
 (0)