![]() |
![]()
| ![]() |
![]()
SYNOPSIStypedef 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(). FUNCTIONSmongoc_structured_log_opts_new()Synopsismongoc_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 VariablesThis is a full list of the captured environment variables.
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.
Note that log level names are always case insensitive. This is a full list of recognized names, including allowed aliases:
ReturnsA newly allocated mongoc_structured_log_opts_t. mongoc_structured_log_opts_destroy()Synopsisvoid mongoc_structured_log_opts_destroy (mongoc_structured_log_opts_t *opts); Parameters
DescriptionThis function releases all resources associated with a mongoc_structured_log_opts_t. Does nothing if opts is NULL. mongoc_structured_log_opts_set_handler()Synopsisvoid mongoc_structured_log_opts_set_handler (mongoc_structured_log_opts_t *opts, 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. Parameters
SEE ALSO: Structured Logging mongoc_structured_log_opts_set_max_level_for_component()Synopsisbool mongoc_structured_log_opts_set_max_level_for_component (mongoc_structured_log_opts_t *opts, 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(). Parameters
ReturnsReturns 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()Synopsisbool mongoc_structured_log_opts_set_max_level_for_all_components (mongoc_structured_log_opts_t *opts, 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. Parameters
ReturnsReturns true on success, or false if the supplied parameters were incorrect. SEE ALSO: Structured Logging mongoc_structured_log_opts_set_max_levels_from_env()Synopsisbool 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. ReturnsReturns 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()Synopsismongoc_structured_log_level_t mongoc_structured_log_opts_get_max_level_for_component (const mongoc_structured_log_opts_t *opts, Parameters
ReturnsReturns 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()Synopsisbool mongoc_structured_log_opts_set_max_document_length (mongoc_structured_log_opts_t *opts, 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. Parameters
ReturnsReturns 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()Synopsisbool 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. ReturnsReturns 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()Synopsissize_t mongoc_structured_log_opts_get_max_document_length (const mongoc_structured_log_opts_t *opts); Parameters
ReturnsReturns the current maximum document length set in opts, as a size_t. SEE ALSO: Structured Logging SEE ALSO: Structured Logging AUTHORMongoDB, Inc COPYRIGHT2009-present, MongoDB, Inc.
|