Agora
1.2.0
Agora project
|
Go to the documentation of this file.
18 #include <bsoncxx/builder/stream/document.hpp>
19 #include <bsoncxx/types.hpp>
20 #include <bsoncxx/view_or_value.hpp>
22 #include <mongocxx/client.hpp>
23 #include <mongocxx/instance.hpp>
24 #include <mongocxx/uri.hpp>
28 template<
typename Mutex>
32 mongo_sink(
const std::string &db_name,
const std::string &collection_name,
const std::string &uri =
"mongodb://localhost:27017")
36 client_ = spdlog::details::make_unique<mongocxx::client>(mongocxx::uri{uri});
40 catch (
const std::exception)
42 throw spdlog_ex(
"Error opening database");
54 using bsoncxx::builder::stream::document;
55 using bsoncxx::builder::stream::finalize;
62 <<
static_cast<int>(msg.
thread_id) << finalize;
73 std::unique_ptr<mongocxx::client>
client_ =
nullptr;
85 template<
typename Factory = spdlog::synchronous_factory>
86 inline std::shared_ptr<logger>
mongo_logger_mt(
const std::string &logger_name,
const std::string &db_name,
87 const std::string &collection_name,
const std::string &uri =
"mongodb://localhost:27017")
89 return Factory::template create<sinks::mongo_sink_mt>(logger_name, db_name, collection_name, uri);
92 template<
typename Factory = spdlog::synchronous_factory>
93 inline std::shared_ptr<logger>
mongo_logger_st(
const std::string &logger_name,
const std::string &db_name,
94 const std::string &collection_name,
const std::string &uri =
"mongodb://localhost:27017")
96 return Factory::template create<sinks::mongo_sink_st>(logger_name, db_name, collection_name, uri);
const SPDLOG_INLINE string_view_t & to_string_view(spdlog::level::level_enum l) SPDLOG_NOEXCEPT
Definition: common-inl.h:23
~mongo_sink()
Definition: mongo_sink.h:46
string_view_t payload
Definition: log_msg.h:30
static mongocxx::instance instance_
Definition: mongo_sink.h:70
std::shared_ptr< logger > mongo_logger_mt(const std::string &logger_name, const std::string &db_name, const std::string &collection_name, const std::string &uri="mongodb://localhost:27017")
Definition: mongo_sink.h:86
std::string db_name_
Definition: mongo_sink.h:71
std::shared_ptr< logger > mongo_logger_st(const std::string &logger_name, const std::string &db_name, const std::string &collection_name, const std::string &uri="mongodb://localhost:27017")
Definition: mongo_sink.h:93
void flush_() override
Definition: mongo_sink.h:67
Definition: base_sink.h:19
mongo_sink(const std::string &db_name, const std::string &collection_name, const std::string &uri="mongodb://localhost:27017")
Definition: mongo_sink.h:32
std::string coll_name_
Definition: mongo_sink.h:72
constexpr auto end() const -> iterator
Definition: core.h:498
string_view_t logger_name
Definition: log_msg.h:20
size_t thread_id
Definition: log_msg.h:23
void sink_it_(const details::log_msg &msg) override
Definition: mongo_sink.h:52
Definition: mongo_sink.h:29
constexpr auto begin() const -> iterator
Definition: core.h:497
level::level_enum level
Definition: log_msg.h:21
constexpr auto data() const -> const Char *
Definition: core.h:492
std::unique_ptr< mongocxx::client > client_
Definition: mongo_sink.h:73
log_clock::time_point time
Definition: log_msg.h:22