1MONGOC_LOGGING(3)              MongoDB C Driver              MONGOC_LOGGING(3)
2
3
4

NAME

6       mongoc_logging - Logging
7
8       MongoDB C driver Logging Abstraction
9

SYNOPSIS

11          typedef enum {
12             MONGOC_LOG_LEVEL_ERROR,
13             MONGOC_LOG_LEVEL_CRITICAL,
14             MONGOC_LOG_LEVEL_WARNING,
15             MONGOC_LOG_LEVEL_MESSAGE,
16             MONGOC_LOG_LEVEL_INFO,
17             MONGOC_LOG_LEVEL_DEBUG,
18             MONGOC_LOG_LEVEL_TRACE,
19          } mongoc_log_level_t;
20
21          #define MONGOC_ERROR(...)
22          #define MONGOC_CRITICAL(...)
23          #define MONGOC_WARNING(...)
24          #define MONGOC_MESSAGE(...)
25          #define MONGOC_INFO(...)
26          #define MONGOC_DEBUG(...)
27
28          typedef void (*mongoc_log_func_t) (mongoc_log_level_t log_level,
29                                             const char *log_domain,
30                                             const char *message,
31                                             void *user_data);
32
33          void
34          mongoc_log_set_handler (mongoc_log_func_t log_func, void *user_data);
35          void
36          mongoc_log (mongoc_log_level_t log_level,
37                      const char *log_domain,
38                      const char *format,
39                      ...) BSON_GNUC_PRINTF (3, 4);
40          const char *
41          mongoc_log_level_str (mongoc_log_level_t log_level);
42          void
43          mongoc_log_default_handler (mongoc_log_level_t log_level,
44                                      const char *log_domain,
45                                      const char *message,
46                                      void *user_data);
47          void
48          mongoc_log_trace_enable (void);
49          void
50          mongoc_log_trace_disable (void);
51
52       The MongoDB C driver comes with an abstraction for logging that you can
53       use in your application, or integrate with an existing logging system.
54

MACROS

56       To make logging a little less painful, various helper macros  are  pro‐
57       vided. See the following example.
58
59          #undef MONGOC_LOG_DOMAIN
60          #define MONGOC_LOG_DOMAIN "my-custom-domain"
61
62          MONGOC_WARNING ("An error occurred: %s", strerror (errno));
63

CUSTOM LOG HANDLERS

65       The  default log handler prints a timestamp and the log message to std‐
66       out, or to stderr for warnings, critical messages, and errors.
67              You can  override  the  handler  with  mongoc_log_set_handler().
68              Your handler function is called in a mutex for thread safety.
69
70       For  example,  you could register a custom handler to suppress messages
71       at INFO level and below:
72
73          void
74          my_logger (mongoc_log_level_t log_level,
75                     const char *log_domain,
76                     const char *message,
77                     void *user_data)
78          {
79             /* smaller values are more important */
80             if (log_level < MONGOC_LOG_LEVEL_INFO) {
81                mongoc_log_default_handler (log_level, log_domain, message, user_data);
82             }
83          }
84
85          int
86          main (int argc, char *argv[])
87          {
88             mongoc_init ();
89             mongoc_log_set_handler (my_logger, NULL);
90
91             /* ... your code ...  */
92
93             mongoc_cleanup ();
94             return 0;
95          }
96
97       To restore the default handler:
98
99          mongoc_log_set_handler (mongoc_log_default_handler, NULL);
100

DISABLE LOGGING

102       To disable all  logging,  including  warnings,  critical  messages  and
103       errors, provide an empty log handler:
104
105          mongoc_log_set_handler (NULL, NULL);
106

TRACING

108       If  compiling your own copy of the MongoDB C driver, consider configur‐
109       ing with -DENABLE_TRACING=ON to enable function tracing and  hex  dumps
110       of  network  packets to STDERR and STDOUT during development and debug‐
111       ging.
112
113       This is especially useful when debugging what may be  going  on  inter‐
114       nally in the driver.
115
116       Trace   messages   can   be   enabled  and  disabled  by  calling  mon‐
117       goc_log_trace_enable() and mongoc_log_trace_disable()
118
119       NOTE:
120          Compiling the driver with -DENABLE_TRACING=ON will affect  its  per‐
121          formance. Disabling tracing with mongoc_log_trace_disable() signifi‐
122          cantly reduces the overhead, but cannot remove it completely.
123

AUTHOR

125       MongoDB, Inc
126
128       2017-present, MongoDB, Inc
129
130
131
132
1331.14.0                           Feb 22, 2019                MONGOC_LOGGING(3)
Impressum