Skip to content

Commit fbc6bab

Browse files
fgalankevinAlbs
authored andcommitted
CDRIVER-3904 improve documentation regarding when to call mongoc_log_set_handler (#739)
1 parent 99a343e commit fbc6bab

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
Initialize the MongoDB C Driver by calling :symbol:`mongoc_init` exactly once at the beginning of your program. It is responsible for initializing global state such as process counters, SSL, and threading primitives.
22

3+
Exception to this is ``mongoc_log_set_handler()``, which should be called before ``mongoc_init()`` or some log traces would not use your log handling function. See :ref:`Custom Log Handlers <custom_log_handlers>` for a detailed example.
4+
35
Call :symbol:`mongoc_cleanup` exactly once at the end of your program to release all memory and other resources allocated by the driver. You must not call any other MongoDB C Driver functions after :symbol:`mongoc_cleanup`. Note that :symbol:`mongoc_init` does **not** reinitialize the driver after :symbol:`mongoc_cleanup`.

src/libmongoc/doc/logging.rst

+5
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ To make logging a little less painful, various helper macros are provided. See t
6565
6666
MONGOC_WARNING ("An error occurred: %s", strerror (errno));
6767
68+
.. _custom_log_handlers:
69+
6870
Custom Log Handlers
6971
-------------------
7072

@@ -100,6 +102,9 @@ For example, you could register a custom handler to suppress messages at INFO le
100102
return 0;
101103
}
102104
105+
Note that in the example above ``mongoc_log_set_handler()`` is called before ``mongoc_init()``.
106+
Otherwise, some log traces could not be processed by the log handler.
107+
103108
To restore the default handler:
104109

105110
.. code-block:: c

0 commit comments

Comments
 (0)