Provided by: libmongoc-doc_1.30.4-1ubuntu1_all bug

SYNOPSIS

          typedef struct mongoc_structured_log_opts_t mongoc_structured_log_opts_t;

       mongoc_structured_log_opts_t  is  an  opaque  type  that  contains  options  for  the  structured logging
       subsystem: per-component log levels, a maximum logged document length, and a handler function.

       Create a mongoc_structured_log_opts_t with mongoc_structured_log_opts_new(), set options and  a  callback
       on       it,       then       pass       it       to      mongoc_client_set_structured_log_opts()      or
       mongoc_client_pool_set_structured_log_opts().        Must       be       destroyed       by       calling
       mongoc_structured_log_opts_destroy().

FUNCTIONS

   mongoc_structured_log_opts_new()
   Synopsis
          mongoc_structured_log_opts_t *
          mongoc_structured_log_opts_new (void);

       Creates a new mongoc_structured_log_opts_t, filled with defaults captured from the current environment.

       Sets a default log handler which would write a text representation of each log message to stderr, stdout,
       or  another  file configurable using MONGODB_LOG_PATH.  This setting has no effect if the default handler
       is replaced using mongoc_structured_log_opts_set_handler().

       Environment variable errors are non-fatal, and result in one-time warnings delivered as  an  unstructured
       log.

       Per-component maximum levels are initialized equivalently to:

          mongoc_structured_log_opts_set_max_level_for_all_components(opts, MONGOC_STRUCTURED_LOG_LEVEL_WARNING);
          mongoc_structured_log_opts_set_max_levels_from_env(opts);

   Environment Variables
       This is a full list of the captured environment variables.

       • MONGODB_LOG_MAX_DOCUMENT_LENGTH:  Maximum length for JSON-serialized documents that appear within a log
         message.   It  may  be  a  number,  in  bytes,  or  unlimited   (case   insensitive)   to   choose   an
         implementation-specific  value  near  the  maximum representable length.  By default, the limit is 1000
         bytes.  This limit affects interior documents like commands and replies, not  the  total  length  of  a
         structured log message.

       • MONGODB_LOG_PATH:  A  file  path  or  one  of  the  special strings stderr or stdout (case insensitive)
         specifying the destination for structured logs seen by the default handler.  By default, it  writes  to
         stderr.   This  path  will  be  captured  during  mongoc_structured_log_opts_new(),  but  it  will  not
         immediately be opened.  If the file can't be opened, a warning is then written to the unstructured  log
         and the handler writes structured logs to stderr instead.

         WARNING:
            When  a  file path is given for MONGODB_LOG_PATH, each log instance (one stand-alone client or pool)
            will separately open this file for append.  The results are operating system specific. On  UNIX-like
            platforms each instance's output will be interleaved, in most cases without splitting individual log
            messages.  Notably  on  Windows  the file will be opened in exclusive mode by the first instance and
            subsequent instances will fail, falling back on  the  default  of  stderr.   Applications  that  use
            multiple  processes or multiple client pools will likely want to supply a log handler that annotates
            each message with information about its originating log instance.

       • MONGODB_LOG_COMMAND:     A     log     level     name     to     set     as     the     maximum     for
         MONGOC_STRUCTURED_LOG_COMPONENT_COMMAND.

       • MONGODB_LOG_TOPOLOGY:     A     log     level     name     to     set     as     the     maximum    for
         MONGOC_STRUCTURED_LOG_COMPONENT_TOPOLOGY.

       • MONGODB_LOG_SERVER_SELECTION:    A    log    level    name    to    set    as    the    maximum     for
         MONGOC_STRUCTURED_LOG_COMPONENT_SERVER_SELECTION.

       • MONGODB_LOG_CONNECTION:     A     log     level     name     to     set     as    the    maximum    for
         MONGOC_STRUCTURED_LOG_COMPONENT_CONNECTION.

       • MONGODB_LOG_ALL: A log level name applied to all components not otherwise specified.

       Note that log level names are always case  insensitive.   This  is  a  full  list  of  recognized  names,
       including allowed aliases:

       • emergency, offalertcriticalerrorwarning, warnnoticeinformational, infodebugtrace

   Returns
       A newly allocated mongoc_structured_log_opts_t.

   mongoc_structured_log_opts_destroy()
   Synopsis
          void
          mongoc_structured_log_opts_destroy (mongoc_structured_log_opts_t *opts);

   Parametersopts:  Pointer  to  a  mongoc_structured_log_opts_t allocated with mongoc_structured_log_opts_new(), or
         NULL.

   Description
       This function releases all resources associated with a  mongoc_structured_log_opts_t.   Does  nothing  if
       opts is NULL.

   mongoc_structured_log_opts_set_handler()
   Synopsis
          void
          mongoc_structured_log_opts_set_handler (mongoc_structured_log_opts_t *opts,
                                                  mongoc_structured_log_func_t log_func,
                                                  void *user_data);

       Sets the function to be called to handle structured log messages, as a mongoc_structured_log_func_t.

       The  callback  is  given a mongoc_structured_log_entry_t as a handle for obtaining additional information
       about the log message.  This entry pointer is only valid during a  callback,  because  it's  a  low  cost
       reference to temporary data.

       Structured  log  handlers  must  be thread-safe if they will be used with mongoc_client_pool_t.  Handlers
       must avoid unbounded recursion, preferably by avoiding the use of any libmongoc client or pool which uses
       the same handler.

       This function always replaces the default log handler from mongoc_structured_log_opts_new(),  if  it  was
       still set.  If the log_func is set to NULL, structured logging will be disabled.

   Parametersopts: Structured log options, allocated with mongoc_structured_log_opts_new().

       • log_func:  The  handler  to  install,  a  mongoc_structured_log_func_t,  or  NULL to disable structured
         logging.

       • user_data: Optional user data, passed on to the handler.

       SEE ALSO:
          Structured Logging

   mongoc_structured_log_opts_set_max_level_for_component()
   Synopsis
          bool
          mongoc_structured_log_opts_set_max_level_for_component (mongoc_structured_log_opts_t *opts,
                                                                  mongoc_structured_log_component_t component,
                                                                  mongoc_structured_log_level_t level);

       Sets the maximum log level per-component.  Only log messages at or below  this  severity  level  will  be
       passed to mongoc_structured_log_func_t.

       By    default,    each    component's   log   level   may   come   from   environment   variables.    See
       mongoc_structured_log_opts_set_max_levels_from_env().

   Parametersopts: Structured log options, allocated with mongoc_structured_log_opts_new().

       • component: The component to set a max log level. for, as a mongoc_structured_log_component_t.

       • level: The new max log level for this component, as a mongoc_structured_log_level_t.

   Returns
       Returns true on success, or false if the supplied parameters were incorrect.

       SEE ALSO:
          Structured Logging

   mongoc_structured_log_opts_set_max_level_for_all_components()
   Synopsis
          bool
          mongoc_structured_log_opts_set_max_level_for_all_components (mongoc_structured_log_opts_t *opts,
                                                                       mongoc_structured_log_level_t level);

       Sets all per-component maximum log levels to the same value.  Only log messages at or below this severity
       level will be passed to mongoc_structured_log_func_t.  Effective even for logging components not known at
       compile-time.

   Parametersopts: Structured log options, allocated with mongoc_structured_log_opts_new().

       • level: The max log level for all components, as a mongoc_structured_log_level_t.

   Returns
       Returns true on success, or false if the supplied parameters were incorrect.

       SEE ALSO:
          Structured Logging

   mongoc_structured_log_opts_set_max_levels_from_env()
   Synopsis
          bool
          mongoc_structured_log_opts_set_max_levels_from_env (mongoc_structured_log_opts_t *opts);

       Sets any maximum log levels requested by  environment  variables:  MONGODB_LOG_ALL  for  all  components,
       followed  by  per-component log levels MONGODB_LOG_COMMAND, MONGODB_LOG_CONNECTION, MONGODB_LOG_TOPOLOGY,
       and MONGODB_LOG_SERVER_SELECTION.

       Expects the value to be recognizable by mongoc_structured_log_get_named_level().  Parse errors may  cause
       a warning message, delivered via unstructured logging.

       Component levels with no valid environment variable setting will be left unmodified.

       This  happens  automatically  when mongoc_structured_log_opts_new() establishes defaults.  Any subsequent
       programmatic modifications to the mongoc_structured_log_opts_t will  override  the  environment  variable
       settings.   For  applications that desire the opposite behavior, where environment variables may override
       programmatic settings, they may call mongoc_structured_log_opts_set_max_levels_from_env()  after  calling
       mongoc_structured_log_opts_set_max_level_for_component()                                              and
       mongoc_structured_log_opts_set_max_level_for_all_components().   This  will  process  the  environment  a
       second time, allowing it to override customized defaults.

   Returns
       Returns  true  on  success.   If  warnings  are encountered in the environment, returns false and may log
       additional information to the unstructured logging facility.  Note that, by design, these errors  are  by
       default  non-fatal.  When mongoc_structured_log_opts_new() internally calls this function, it ignores the
       return value.

       SEE ALSO:
          Structured Logging

   mongoc_structured_log_opts_get_max_level_for_component()
   Synopsis
          mongoc_structured_log_level_t
          mongoc_structured_log_opts_get_max_level_for_component (const mongoc_structured_log_opts_t *opts,
                                                                  mongoc_structured_log_component_t component);

   Parametersopts: Structured log options, allocated with mongoc_structured_log_opts_new().

       • component: Log component as a mongoc_structured_log_component_t.

   Returns
       Returns the configured maximum log level for a specific component,  as  a  mongoc_structured_log_level_t.
       This   may  be  the  last  value  set  with  mongoc_structured_log_opts_set_max_level_for_component()  or
       mongoc_structured_log_opts_set_max_level_for_all_components(), or it may be  the  default  obtained  from
       environment variables.  If an invalid or unknown component enum is given, returns the lowest log level.

       SEE ALSO:
          Structured Logging

   mongoc_structured_log_opts_set_max_document_length()
   Synopsis
          bool
          mongoc_structured_log_opts_set_max_document_length (mongoc_structured_log_opts_t *opts,
                                                              size_t max_document_length);

       Sets  a maximum length for BSON documents that appear serialized in JSON form as part of a structured log
       message.

       Serialized JSON will be truncated at  this  limit,  interpreted  as  a  count  of  UTF-8  encoded  bytes.
       Truncation  will  be indicated with a ... suffix, the length of which is not included in the max document
       length. If truncation at the exact indicated length would  split  a  valid  UTF-8  sequence,  we  instead
       truncate the document earlier at the nearest boundary between code points.

   Parametersopts: Structured log options, allocated with mongoc_structured_log_opts_new().

       • max_document_length:  Maximum  length  for  each  embedded  JSON  document,  in bytes, not including an
         ellipsis (...) added to indicate truncation. Values near or above INT_MAX will be rejected.

   Returns
       Returns true on success, or false if the supplied maximum length is too large.

       SEE ALSO:
          Structured Logging
          mongoc_structured_log_opts_set_max_document_length_from_env()

   mongoc_structured_log_opts_set_max_document_length_from_env()
   Synopsis
          bool
          mongoc_structured_log_opts_set_max_document_length_from_env (mongoc_structured_log_opts_t *opts);

       Sets a maximum document length from the MONGODB_LOG_MAX_DOCUMENT_LENGTH environment variable, if a  valid
       setting  is  found.   See mongoc_structured_log_opts_new() for a description of the supported environment
       variable formats.

       Parse errors may cause a warning message, delivered via unstructured logging.

       This happens automatically when mongoc_structured_log_opts_new() establishes  defaults.   Any  subsequent
       programmatic  modifications  to  the  mongoc_structured_log_opts_t will override the environment variable
       settings.  For applications that desire the opposite behavior, where environment variables  may  override
       programmatic  settings, they may call mongoc_structured_log_opts_set_max_document_length_from_env() after
       calling mongoc_structured_log_opts_set_max_document_length().  This will process the environment a second
       time, allowing it to override customized defaults.

   Returns
       Returns true on success: either a valid environment setting was found, or the value  is  unset  and  opts
       will  not  be  modified.   If  warnings  are  encountered  in  the environment, returns false and may log
       additional information to the unstructured logging facility.  Note that, by design, these errors  are  by
       default  non-fatal.  When mongoc_structured_log_opts_new() internally calls this function, it ignores the
       return value.

       SEE ALSO:
          Structured Logging

   mongoc_structured_log_opts_get_max_document_length()
   Synopsis
          size_t
          mongoc_structured_log_opts_get_max_document_length (const mongoc_structured_log_opts_t *opts);

   Parametersopts: Structured log options, allocated with mongoc_structured_log_opts_new().

   Returns
       Returns the current maximum document length set in opts, as a size_t.

       SEE ALSO:
          Structured Logging

       SEE ALSO:
          Structured Logging

AUTHOR

       MongoDB, Inc

COPYRIGHT

       2009-present, MongoDB, Inc.

1.30.4                                            Jun 08, 2025                   MONGOC_STRUCTURED_LOG_OPTS_T(3)