How to use a custom logger with a MongoDB C++ Driver instance.
Basic Usage
private:
int* counter_ptr;
public:
explicit example_logger(int* ptr) : counter_ptr(ptr) {}
bsoncxx::stdx::string_view domain,
bsoncxx::stdx::string_view message) noexcept override {
EXPECT(level == mongocxx::log_level::k_info);
EXPECT(domain == "mongocxx");
EXPECT(message == "libmongoc logging callback enabled");
*counter_ptr += 1;
}
};
void example() {
int counter = 0;
auto logger = std::unique_ptr<mongocxx::logger>(new example_logger{&counter});
EXPECT(counter == 1);
}
Convert a Log Level to a String
void example() {
EXPECT(error == "error");
EXPECT(critical == "critical");
EXPECT(warning == "warning");
EXPECT(message == "message");
EXPECT(info == "info");
EXPECT(debug == "debug");
EXPECT(trace == "trace");
}