MongoDB C++ Driver current
Loading...
Searching...
No Matches
logger.hpp
Go to the documentation of this file.
1// Copyright 2009-present MongoDB, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <mongocxx/v1/logger-fwd.hpp> // IWYU pragma: export
18
19//
20
22
25
27
28#include <functional>
29#include <memory>
30
31namespace mongocxx {
32namespace v1 {
33
46
48
71
72BSONCXX_PRIVATE_WARNINGS_PUSH();
73BSONCXX_PRIVATE_WARNINGS_DISABLE(MSVC(4251));
74BSONCXX_PRIVATE_WARNINGS_DISABLE(MSVC(4275));
75
81class logger {
82 public:
86 virtual ~logger();
87
91 logger(logger&&) = default;
92
96 logger& operator=(logger&&) = default;
97
101 logger(logger const&) = default;
102
106 logger& operator=(logger const&) = default;
107
111 logger() = default;
112
126 virtual void operator()(
127 log_level level,
129 bsoncxx::v1::stdx::string_view message) noexcept = 0;
130};
131
132BSONCXX_PRIVATE_WARNINGS_POP();
133
138
162
174
198 private:
199 class impl;
200 std::unique_ptr<impl> _impl;
201
202 public:
208
213
218
222 logger_guard(logger_guard const&) = delete;
223
228
235
242};
243
244} // namespace v1
245} // namespace mongocxx
246
247#include <mongocxx/v1/detail/postlude.hpp>
248
For internal use only!
A polyfill for std::string_view.
Definition string_view.hpp:412
logger_guard(logger_guard &&)=delete
This class is not moveable.
logger(logger &&)=default
Move constructor.
A tag type representing mongoc's default unstructured log handler.
Definition logger.hpp:137
logger_guard & operator=(logger_guard const &)=delete
This class is not copyable.
~logger_guard()
Restore the unstructured log message handler that was active when this guard was constructed.
logger_guard(logger_guard &&)=delete
This class is not moveable.
logger_guard & operator=(logger_guard &&)=delete
This class is not moveable.
logger_guard(logger_guard const &)=delete
This class is not copyable.
logger(logger const &)=default
Copy constructor.
logger & operator=(logger &&)=default
Move assignment operator.
virtual ~logger()
Destructor.
logger()=default
Default constructor.
virtual void operator()(log_level level, bsoncxx::v1::stdx::string_view domain, bsoncxx::v1::stdx::string_view message) noexcept=0
Handle an unstructured log message emitted by mongoc.
logger(logger &&)=default
Move constructor.
logger & operator=(logger const &)=default
Copy assignment operator.
Provides macros to control the set of symbols exported in the ABI.
#define MONGOCXX_ABI_CDECL
Expands to __cdecl when built with MSVC on Windows.
Definition export.hpp:49
#define MONGOCXX_ABI_EXPORT_CDECL(...)
Equivalent to MONGOCXX_ABI_EXPORT with MONGOCXX_ABI_CDECL.
Definition export.hpp:52
The mongocxx v1 macro guard prelude header.
Declares entities whose ABI stability is guaranteed for documented symbols.
void set_global_logger(log_handler handler)
Set the process-global unstructured log message handler to a custom handler.
log_level
The log level for an unstructured log message.
Definition logger.hpp:37
@ k_debug
MONGOC_LOG_LEVEL_DEBUG.
Definition logger.hpp:43
@ k_warning
MONGOC_LOG_LEVEL_WARNING.
Definition logger.hpp:40
@ k_trace
MONGOC_LOG_LEVEL_TRACE.
Definition logger.hpp:44
@ k_error
MONGOC_LOG_LEVEL_ERROR.
Definition logger.hpp:38
@ k_critical
MONGOC_LOG_LEVEL_CRITICAL.
Definition logger.hpp:39
@ k_message
MONGOC_LOG_LEVEL_MESSAGE.
Definition logger.hpp:41
@ k_info
MONGOC_LOG_LEVEL_INFO.
Definition logger.hpp:42
std::function< void(log_level, bsoncxx::v1::stdx::string_view, bsoncxx::v1::stdx::string_view)> log_handler
The type of an unstructured log message handler.
Definition logger.hpp:69
The top-level namespace within which all mongocxx library entities are declared.
Declares mongocxx::v1::logger.
Provides std::string_view-related polyfills for library API usage.