|
This is the original logging facility that supports freeform string messages originating from the driver itself or from application code. This has been retroactively termed "unstructured logging". See Structured Logging for the newer standardized logging facility. typedef enum {
This abstraction can be used for logging in your application, or you can integrate the driver with an existing logging system. MACROSTo 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));
CUSTOM LOG HANDLERSThe default log handler prints a timestamp and the log message to stdout, or to stderr for warnings, critical messages, and errors. You can override the handler with mongoc_log_set_handler(). Your handler function is called in a mutex for thread safety. 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, 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); DISABLE LOGGINGTo disable all logging, including warnings, critical messages and errors, provide an empty log handler: mongoc_log_set_handler (NULL, NULL); TRACINGIf 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: Compiling the driver with -DENABLE_TRACING=ON will
affect its performance. Disabling tracing with
mongoc_log_trace_disable() significantly reduces the overhead, but
cannot remove it completely.
AUTHORMongoDB, Inc COPYRIGHT2009-present, MongoDB, Inc.
|