MACROS
- Provided by: libmongoc-doc (Version: 1.26.0-1.1ubuntu2)
- Source: mongo-c-driver
- Report a bug
MongoDB C driver Logging Abstraction
To make logging a little less painful, various helper macros are provided. See the following example.
#undef MONGOC_LOG_DOMAIN
#define MONGOC_LOG_DOMAIN "my-custom-domain"
MONGOC_WARNING ("An error occurred: %s", strerror (errno));
For example, you could register a custom handler to suppress messages at INFO level and below:
void
my_logger (mongoc_log_level_t log_level,
const char *log_domain,
const char *message,
void *user_data)
{
/* smaller values are more important */
if (log_level < MONGOC_LOG_LEVEL_INFO) {
mongoc_log_default_handler (log_level, log_domain, message, user_data);
}
}
int
main (int argc, char *argv[])
{
mongoc_log_set_handler (my_logger, NULL);
mongoc_init ();
/* ... your code ... */
mongoc_cleanup ();
return 0;
}
Note that in the example above mongoc_log_set_handler() is called before mongoc_init(). Otherwise, some log traces could not be processed by the log handler.
To restore the default handler:
mongoc_log_set_handler (mongoc_log_default_handler, NULL);
To disable all logging, including warnings, critical messages and errors, provide an empty log handler:
mongoc_log_set_handler (NULL, NULL);
If compiling your own copy of the MongoDB C driver, consider configuring with -DENABLE_TRACING=ON to enable function tracing and hex dumps of network packets to STDERR and STDOUT during development and debugging.
This is especially useful when debugging what may be going on internally in the driver.
Trace messages can be enabled and disabled by calling mongoc_log_trace_enable() and mongoc_log_trace_disable()
NOTE:
MongoDB, Inc
2017-present, MongoDB, Inc