MongoDB C++ Driver current
Loading...
Searching...
No Matches
mongocxx::v1::logger_guard Class Reference

#include <mongocxx/v1/logger.hpp>

Description

A scope guard to temporarily replace the current unstructured log message handler.

On construction, captures the current global logging configuration and installs the requested handler. On destruction, restores the captured configuration. Nesting is supported: guards restore each prior handler in reverse order of construction.

// ... mongoc's default handler is active ...
{
mongocxx::v1::logger_guard guard{[](auto level, auto domain, auto message) { ... }};
// ... the custom handler is active ...
}
// ... mongoc's default handler is active again ...
An instance of the MongoDB C++ Driver.
Definition instance.hpp:64
A scope guard to temporarily replace the current unstructured log message handler.
Definition logger.hpp:197
Warning
Construction and destruction are NOT thread-safe with respect to unstructured logging. See mongocxx::v1::set_global_logger.
Important
All guards must be within the lifetime of the mongocxx::v1::instance object.

Public Member Functions

 logger_guard (log_handler handler)
 Register a custom unstructured log message handler for the lifetime of this guard.
 logger_guard (logger_guard &&)=delete
 This class is not moveable.
 logger_guard (logger_guard const &)=delete
 This class is not copyable.
 logger_guard (v1::default_logger tag)
 Register mongoc's default unstructured log message handler for the lifetime of this guard.
 ~logger_guard ()
 Restore the unstructured log message handler that was active when this guard was constructed.
logger_guardoperator= (logger_guard &&)=delete
 This class is not moveable.
logger_guardoperator= (logger_guard const &)=delete
 This class is not copyable.

Constructor & Destructor Documentation

◆ ~logger_guard()

mongocxx::v1::logger_guard::~logger_guard ( )

Restore the unstructured log message handler that was active when this guard was constructed.

◆ logger_guard() [1/4]

mongocxx::v1::logger_guard::logger_guard ( logger_guard && )
delete

This class is not moveable.

◆ logger_guard() [2/4]

mongocxx::v1::logger_guard::logger_guard ( logger_guard const & )
delete

This class is not copyable.

◆ logger_guard() [3/4]

mongocxx::v1::logger_guard::logger_guard ( log_handler handler)
explicit

Register a custom unstructured log message handler for the lifetime of this guard.

Parameters
handlerThe handler to register. Disable unstructured logging when null (empty).

◆ logger_guard() [4/4]

mongocxx::v1::logger_guard::logger_guard ( v1::default_logger tag)
explicit

Register mongoc's default unstructured log message handler for the lifetime of this guard.

Parameters
tagUnused: only for overload resolution.

Member Function Documentation

◆ operator=() [1/2]

logger_guard & mongocxx::v1::logger_guard::operator= ( logger_guard && )
delete

This class is not moveable.

◆ operator=() [2/2]

logger_guard & mongocxx::v1::logger_guard::operator= ( logger_guard const & )
delete

This class is not copyable.


The documentation for this class was generated from the following file: