12 #include <unordered_map>
16 #include <spdlog/async.h>
17 #include <spdlog/spdlog.h>
18 #include <spdlog/async_logger.h>
19 #include <spdlog/pattern_formatter.h>
20 #include <spdlog/sinks/basic_file_sink.h>
21 #include <spdlog/sinks/daily_file_sink.h>
22 #include <spdlog/sinks/null_sink.h>
23 #include <spdlog/sinks/rotating_file_sink.h>
24 #include <spdlog/sinks/stdout_color_sinks.h>
25 #include <spdlog/sinks/stdout_sinks.h>
27 #include <spdlog/sinks/syslog_sink.h>
29 #include <spdlog/sinks/msvc_sink.h>
48 static auto const stdStrs{ std::vector<std::string>{
"stdout_sink_st",
"stdout_sink_mt",
"stdout_color_sink_st",
49 "stdout_color_sink_mt",
"color_stdout_sink_st",
50 "color_stdout_sink_mt",
"stderr_sink_st",
"stderr_sink_mt",
51 "stderr_color_sink_st",
"stderr_color_sink_mt",
52 "color_stderr_sink_st",
"color_stderr_sink_mt" } };
59 static auto const fileStrs{ std::vector<std::string>{
"basic_file_sink_st",
"basic_file_sink_mt" } };
66 static auto const rotateStrs{ std::vector<std::string>{
"rotating_file_sink_st",
"rotating_file_sink_mt" } };
73 static auto const dailyStrs{ std::vector<std::string>{
"daily_file_sink_st",
"daily_file_sink_mt" } };
80 static auto const nullStrs{ std::vector<std::string>{
"null_sink_st",
"null_sink_mt" } };
87 static auto const linuxStrs{ std::vector<std::string>{
"syslog_sink_st",
"syslog_sink_mt" } };
94 static auto const winStrs{ std::vector<std::string>{
"msvc_sink_st",
"msvc_sink_mt" } };
101 static auto const levelMap{ std::unordered_map<std::string, spdlog::level::level_enum>{
102 {
"critical", spdlog::level::level_enum::critical },
103 {
"debug", spdlog::level::level_enum::debug },
104 {
"err", spdlog::level::level_enum::err },
105 {
"info", spdlog::level::level_enum::info },
106 {
"n_levels", spdlog::level::level_enum::n_levels },
107 {
"off", spdlog::level::level_enum::off },
108 {
"trace", spdlog::level::level_enum::trace },
109 {
"warn", spdlog::level::level_enum::warn },
118 static auto const overflowMap{ std::map<toml::string, spdlog::async_overflow_policy>{
119 {
"overrun_oldest", spdlog::async_overflow_policy::overrun_oldest },
120 {
"block", spdlog::async_overflow_policy::block },
139 static auto sinkMap() -> std::map<toml::string, spdlog::sink_ptr>
const &;
149 static auto patternMap() -> std::map<toml::string, toml::string>
const &;
159 static auto threadPoolMap() -> std::map<toml::string, std::pair<std::size_t, std::size_t>>
const &;
169 static void emplaceSinkMap(std::pair<toml::string, spdlog::sink_ptr> &&_pr);
192 static void emplaceThreadPoolMap(std::pair<toml::string, std::pair<std::size_t, std::size_t>> &&_pr);
201 static inline std::map<toml::string, spdlog::sink_ptr>
mSinkMap{};
219 static inline std::map<toml::string, std::pair<std::size_t, std::size_t>>
mThreadPoolMap{};
226 #define createRotatingFileSinkStPtr createRotatingFileSinkPtr<spdlog::details::null_mutex>
232 #define createRotatingFileSinkMtPtr createRotatingFileSinkPtr<std::mutex>
238 #define createFileSinkStPtr createFileSinkPtr<spdlog::details::null_mutex>
244 #define createFileSinkMtPtr createFileSinkPtr<std::mutex>
250 #define createDailyFileSinkStPtr createDailyFileSinkPtr<spdlog::details::null_mutex>
256 #define createDailyFileSinkMtPtr createDailyFileSinkPtr<std::mutex>
262 #define createStdoutSinkStPtr createStdoutSinkPtr<spdlog::details::console_nullmutex>
268 #define createStdoutSinkMtPtr createStdoutSinkPtr<spdlog::details::console_mutex>
270 #define createStderrSinkStPtr createStderrSinkPtr<spdlog::details::console_nullmutex>
271 #define createStderrSinkMtPtr createStderrSinkPtr<spdlog::details::console_mutex>
277 #define createStdoutColorSinkStPtr createStdoutColorSinkPtr<spdlog::details::console_nullmutex>
283 #define createStdoutColorSinkMtPtr createStdoutColorSinkPtr<spdlog::details::console_mutex>
285 #define createStderrColorSinkStPtr createStderrColorSinkPtr<spdlog::details::console_nullmutex>
286 #define createStderrColorSinkMtPtr createStderrColorSinkPtr<spdlog::details::console_mutex>
293 #define createSyslogSinkStPtr createSyslogSinkPtr<spdlog::details::null_mutex>
299 #define createSyslogSinkMtPtr createSyslogSinkPtr<std::mutex>
306 #define createMsvcSinkStPtr createMsvcSinkPtr<spdlog::details::null_mutex>
312 #define createMsvcSinkMtPtr createMsvcSinkPtr<std::mutex>
326 bool inTypelist(std::string
const &typeStr, std::vector<std::string>
const &strList);
343 std::size_t
const &maxFiles)
344 -> std::tuple<toml::string const, std::size_t const, std::size_t const>;
360 template<
typename Mutex>
362 std::size_t
const &maxFiles)
363 -> std::shared_ptr<spdlog::sinks::rotating_file_sink<Mutex>>
366 return std::make_shared<spdlog::sinks::rotating_file_sink<Mutex>>(std::get<0>(tup), std::get<1>(tup),
381 -> std::tuple<toml::string const, bool const>;
396 template<
typename Mutex>
398 -> std::shared_ptr<spdlog::sinks::basic_file_sink<Mutex>>
401 return std::make_shared<spdlog::sinks::basic_file_sink<Mutex>>(std::get<0>(tup), std::get<1>(tup));
420 uint16_t
const &maxFiles)
421 -> std::tuple<toml::string const, int const, int const, bool const, uint16_t const>;
438 template<
typename Mutex>
440 uint16_t
const &maxFiles) -> std::shared_ptr<spdlog::sinks::daily_file_sink<Mutex>>
443 return std::make_shared<spdlog::sinks::daily_file_sink<Mutex>>(std::get<0>(tup), std::get<1>(tup), std::get<2>(tup),
444 std::get<3>(tup), std::get<4>(tup));
453 auto createNullSinkPtr() -> std::shared_ptr<spdlog::sinks::null_sink<spdlog::details::null_mutex>>;
464 template<
typename Mutex>
467 return std::make_shared<spdlog::sinks::stdout_sink<Mutex>>();
470 template<
typename Mutex>
473 return std::make_shared<spdlog::sinks::stderr_sink<Mutex>>();
487 template<
typename Mutex>
490 return std::make_shared<spdlog::sinks::wincolor_stdout_sink<Mutex>>();
493 template<
typename Mutex>
496 return std::make_shared<spdlog::sinks::wincolor_stderr_sink<Mutex>>();
510 template<
typename Mutex>
513 return std::make_shared<spdlog::sinks::ansicolor_stdout_sink<Mutex>>();
516 template<
typename Mutex>
519 return std::make_shared<spdlog::sinks::ansicolor_stderr_sink<Mutex>>();
537 auto createSyslogSinkTuple(toml::table
const &sinkTable)
538 -> std::tuple<toml::string const, int const, int const, bool const>;
552 template<
typename Mutex>
553 auto createSyslogSinkPtr(toml::table &&sinkTable) -> std::shared_ptr<spdlog::sinks::syslog_sink<Mutex>>
555 auto tup = createSyslogSinkTuple(std::move(sinkTable));
556 return std::make_shared<spdlog::sinks::syslog_sink<Mutex>>(std::get<0>(tup), std::get<1>(tup), std::get<2>(tup),
570 template<
typename Mutex>
571 auto createMsvcSinkPtr() -> std::shared_ptr<spdlog::sinks::msvc_sink<Mutex>>
573 return std::make_shared<spdlog::sinks::msvc_sink<Mutex>>();
587 auto genFromFileStr(toml::string &&typeStr, toml::table &&sinkTable,
bool const &truncate) -> spdlog::sink_ptr;
600 auto genFromRotateStr(toml::string &&typeStr, toml::table &&sinkTable, toml::string &&baseFilename,
601 std::size_t
const &maxFiles) -> spdlog::sink_ptr;
615 auto genFromDailyStr(toml::string &&typeStr, toml::table &&sinkTable,
bool const &truncate,
616 toml::string &&baseFilename, uint16_t
const &maxFiles) -> spdlog::sink_ptr;
639 auto genFromLinuxStr(toml::string &&typeStr, toml::table &&sinkTable) -> spdlog::sink_ptr;
650 auto genFromWinStr(toml::string &&typeStr) -> spdlog::sink_ptr;
This class contains maps that associate string names to sink pointers, format strings,...
static std::map< toml::string, spdlog::sink_ptr > mSinkMap
Map that associates string names to sink pointers. When sink pointers are created from sink tables in...
static void emplaceSinkMap(std::pair< toml::string, spdlog::sink_ptr > &&_pr)
Emplace a pair in the private member KDSPDSetup::details::SPDMaps::mSinkMap. This function is called ...
static std::map< toml::string, std::pair< std::size_t, std::size_t > > mThreadPoolMap
Map that associates string names to pairs of thread pool fields. The pairs represent the queue size a...
static auto sinkMap() -> std::map< toml::string, spdlog::sink_ptr > const &
Getter method for the private member KDSPDSetup::details::SPDMaps::mSinkMap. Used to index the map an...
static auto patternMap() -> std::map< toml::string, toml::string > const &
Getter method for the private member KDSPDSetup::details::SPDMaps::mPatternMap. Used to index the map...
static auto threadPoolMap() -> std::map< toml::string, std::pair< std::size_t, std::size_t >> const &
Getter method for the private member KDSPDSetup::details::SPDMaps::mThreadPoolMap....
static void emplaceThreadPoolMap(std::pair< toml::string, std::pair< std::size_t, std::size_t >> &&_pr)
Emplace a pair in the private member KDSPDSetup::details::SPDMaps::mThreadPoolMap....
static void emplacePatternMap(std::pair< toml::string, toml::string > &&_pr)
Emplace a pair in the private member KDSPDSetup::details::SPDMaps::mSinkMap. This function is called ...
static std::map< toml::string, toml::string > mPatternMap
Map that associates string names to pattern strings. When pattern tables are read from a configuratio...
This namespace contains implementation details and helpers used by functions in KDSPDSetup::setup....
static auto const linuxStrs
Vector of strings of spdlog syslog sink typenames. Used when matching a type string from a TOML table...
static auto const dailyStrs
Vector of strings of spdlog daily file sink typenames. Used when matching a type string from a TOML t...
static auto const nullStrs
Vector of strings of spdlog null sink typenames. Used when matching a type string from a TOML table t...
auto genFromDailyStr(toml::string &&typeStr, toml::table &&sinkTable, bool const &truncate, toml::string &&baseFilename, uint16_t const &maxFiles) -> spdlog::sink_ptr
Return the result of calling KDSPDSetup::details::createDailyFileSinkPtr with the correct template ar...
static auto const fileStrs
Vector of strings of spdlog basic file sink typenames. Used when matching a type string from a TOML t...
bool inTypelist(std::string const &typeStr, std::vector< std::string > const &strList)
Returns true if a string typeStr is present in a vector strList, and false if not....
static auto const rotateStrs
Vector of strings of spdlog rotating file sink typenames. Used when matching a type string from a TOM...
auto createStderrSinkPtr() -> std::shared_ptr< spdlog::sinks::stderr_sink< Mutex >>
static auto const winStrs
Vector of strings of spdlog MSVC sink typenames. Used when matching a type string from a TOML table t...
auto createNullSinkPtr() -> std::shared_ptr< spdlog::sinks::null_sink< spdlog::details::null_mutex >>
Create a null sink shared pointer and return it.
auto createFileSinkTuple(toml::table const &sinkTable, bool const &truncate) -> std::tuple< toml::string const, bool const >
Generates the argument list for basic file sink constructor as a tuple and returns it....
static auto const overflowMap
A simple map associating strings of spdlog::async_overflow_policy names to the enums themselves....
auto genFromFileStr(toml::string &&typeStr, toml::table &&sinkTable, bool const &truncate) -> spdlog::sink_ptr
Return the result of calling KDSPDSetup::details::createFileSinkPtr with the correct template argumen...
auto genFromRotateStr(toml::string &&typeStr, toml::table &&sinkTable, toml::string &&baseFilename, std::size_t const &maxFiles) -> spdlog::sink_ptr
Return the result of calling KDSPDSetup::details::createRotatingFileSinkPtr with the correct template...
auto createStdoutColorSinkPtr() -> std::shared_ptr< spdlog::sinks::ansicolor_stdout_sink< Mutex >>
Create an color standard output sink shared pointer and return it. The macros createStdoutColorSinkSt...
auto createStderrColorSinkPtr() -> std::shared_ptr< spdlog::sinks::ansicolor_stderr_sink< Mutex >>
auto createStdoutSinkPtr() -> std::shared_ptr< spdlog::sinks::stdout_sink< Mutex >>
Create a standard output sink shared pointer and return it. The macros createStdoutSinkStPtr and crea...
auto createRotatingFileSinkTuple(toml::table const &sinkTable, toml::string &&baseFilename, std::size_t const &maxFiles) -> std::tuple< toml::string const, std::size_t const, std::size_t const >
Generates the argument list for rotating file sink constructor as a tuple and returns it....
static auto const levelMap
A simple map associating strings of spdlog::level::level_enum names to the enums themselves....
auto createDailyFileSinkTuple(toml::table &&sinkTable, bool const &truncate, toml::string &&baseFilename, uint16_t const &maxFiles) -> std::tuple< toml::string const, int const, int const, bool const, uint16_t const >
Generates the argument list for daily file sink constructor as a tuple and returns it....
auto createRotatingFileSinkPtr(toml::table const &sinkTable, toml::string &&baseFilename, std::size_t const &maxFiles) -> std::shared_ptr< spdlog::sinks::rotating_file_sink< Mutex >>
Create a rotating file sink shared pointer and return it. Calls KDSPDSetup::details::createRotatingFi...
auto createDailyFileSinkPtr(toml::table &&sinkTable, bool const &truncate, toml::string &&baseFilename, uint16_t const &maxFiles) -> std::shared_ptr< spdlog::sinks::daily_file_sink< Mutex >>
Create a daily file sink shared pointer and return it. Calls KDSPDSetup::details::createDailyFileSink...
auto createFileSinkPtr(toml::table const &sinkTable, bool const &truncate) -> std::shared_ptr< spdlog::sinks::basic_file_sink< Mutex >>
Create a basic file sink shared pointer and return it. Calls KDSPDSetup::details::createFileSinkTuple...
auto genFromNullOrStdStr(toml::string &&typeStr) -> spdlog::sink_ptr
Return the result of calling KDSPDSetup::details::createStdoutSinkPtr with the correct template argum...
static auto const stdStrs
Vector of strings of spdlog standard output sink typenames. Used when matching a type string from a T...