---
name: "mongoc_structured_log_opts_set_handler"
section: "3"
platform: "linux"
package: "libmongoc-doc"
version: "1.30.4-1+deb13u3"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/mongoc_structured_log_opts_set_handler"
---

# mongoc\_structured\_log\_opts\_set\_handler(3)

## 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.

## PARAMETERS

- •

  **opts**: 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
```

## AUTHOR

MongoDB, Inc

## COPYRIGHT

2009-present, MongoDB, Inc.
