KDSPDSetup
Small library to initialize spdlog loggers from a toml configuration file.
details.h File Reference
#include <unordered_map>
#include <map>
#include <vector>
#include <spdlog/async.h>
#include <spdlog/spdlog.h>
#include <spdlog/async_logger.h>
#include <spdlog/pattern_formatter.h>
#include <spdlog/sinks/basic_file_sink.h>
#include <spdlog/sinks/daily_file_sink.h>
#include <spdlog/sinks/null_sink.h>
#include <spdlog/sinks/rotating_file_sink.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/sinks/stdout_sinks.h>
#include <toml.hpp>
Include dependency graph for details.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  KDSPDSetup::details::SPDMaps
 This class contains maps that associate string names to sink pointers, format strings, and thread pool information. This enables simple access of these objects by name when constructing loggers. There are no instances of the class - it is composed entirely of static members. More...
 

Namespaces

 KDSPDSetup
 The only public-facing namespace in the library.
 
 KDSPDSetup::details
 This namespace contains implementation details and helpers used by functions in KDSPDSetup::setup. This includes lookup for sink types and spdlog enums, maps to contain named sinks, patterns, and thread pools (to be used when constructing loggers), and functions that actually construct sink pointers of specific types.
 

Macros

#define createRotatingFileSinkStPtr   createRotatingFileSinkPtr<spdlog::details::null_mutex>
 A macro alias to improve readability of calls to KDSPDSetup::details::createRotatingFileSinkPtr. More...
 
#define createRotatingFileSinkMtPtr   createRotatingFileSinkPtr<std::mutex>
 A macro alias to improve readability of calls to KDSPDSetup::details::createRotatingFileSinkPtr. More...
 
#define createFileSinkStPtr   createFileSinkPtr<spdlog::details::null_mutex>
 A macro alias to improve readability of calls to KDSPDSetup::details::createFileSinkPtr. More...
 
#define createFileSinkMtPtr   createFileSinkPtr<std::mutex>
 A macro alias to improve readability of calls to KDSPDSetup::details::createFileSinkPtr. More...
 
#define createDailyFileSinkStPtr   createDailyFileSinkPtr<spdlog::details::null_mutex>
 A macro alias to improve readability of calls to KDSPDSetup::details::createDailyFileSinkPtr. More...
 
#define createDailyFileSinkMtPtr   createDailyFileSinkPtr<std::mutex>
 A macro alias to improve readability of calls to KDSPDSetup::details::createDailyFileSinkPtr. More...
 
#define createStdoutSinkStPtr   createStdoutSinkPtr<spdlog::details::console_nullmutex>
 A macro alias to improve readability of calls to KDSPDSetup::details::createStdoutSinkPtr. More...
 
#define createStdoutSinkMtPtr   createStdoutSinkPtr<spdlog::details::console_mutex>
 A macro alias to improve readability of calls to KDSPDSetup::details::createStdoutSinkPtr. More...
 
#define createStderrSinkStPtr   createStderrSinkPtr<spdlog::details::console_nullmutex>
 
#define createStderrSinkMtPtr   createStderrSinkPtr<spdlog::details::console_mutex>
 
#define createStdoutColorSinkStPtr   createStdoutColorSinkPtr<spdlog::details::console_nullmutex>
 A macro alias to improve readability of calls to KDSPDSetup::details::createStdoutColorSinkPtr. More...
 
#define createStdoutColorSinkMtPtr   createStdoutColorSinkPtr<spdlog::details::console_mutex>
 A macro alias to improve readability of calls to KDSPDSetup::details::createStdoutColorSinkPtr. More...
 
#define createStderrColorSinkStPtr   createStderrColorSinkPtr<spdlog::details::console_nullmutex>
 
#define createStderrColorSinkMtPtr   createStderrColorSinkPtr<spdlog::details::console_mutex>
 

Functions

bool KDSPDSetup::details::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. Used to identify a group to which a sink's type belongs when reading from a configuration file. This grouping informs what additional fields should be extracted and narrows down which constructors to call to create a sink. More...
 
auto KDSPDSetup::details::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. Given a TOML table representing a rotating file sink, a base filename, and a number of maximum files, extract and calculate the maximum file size from the table, and create a tuple with the base filename, max size, and max number of files in the correct order. Return this tuple so the values can be passed into the constructor for rotating file sink, in that order. More...
 
template<typename Mutex >
auto KDSPDSetup::details::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::createRotatingFileSinkTuple to evaluate the arguments to pass into the constructor, and calls the constructor with those arguments. The macros createRotatingFileSinkStPtr and createRotatingFileSinkMtPtr exist to improve readability and clarity of intent when calling this function. More...
 
auto KDSPDSetup::details::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. Given a TOML table representing a basic file sink and a boolean value for truncate, extract the filename from the table, and create a tuple with the filename and truncate in the order in which they will be passed into the basic file sink constructor. Return this tuple. More...
 
template<typename Mutex >
auto KDSPDSetup::details::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 to evaluate the arguments to pass into the constructor, and calls the constructor with those arguments. The macros createFileSinkStPtr and createFileSinkMtPtr exist to improve readability and clarity of intent when calling this function. More...
 
auto KDSPDSetup::details::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. Given a TOML table representing a basic file sink, a base filename, and a number of maximum files, and a boolean value for truncate, extract the rotation_hour and rotation_minute from the table, and create a tuple with the base filename, rotation hour, rotation minute, truncate, and maximum file count in the order in which they will be passed to the basic file sink constructor. Return this tuple. More...
 
template<typename Mutex >
auto KDSPDSetup::details::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::createDailyFileSinkTuple to evaluate the arguments to pass into the constructor, and calls the constructor with those arguments. The macros createDailyFileSinkStPtr and createDailyFileSinkMtPtr exist to improve readability and clarity of intent when calling this function. More...
 
auto KDSPDSetup::details::createNullSinkPtr () -> std::shared_ptr< spdlog::sinks::null_sink< spdlog::details::null_mutex >>
 Create a null sink shared pointer and return it. More...
 
template<typename Mutex >
auto KDSPDSetup::details::createStdoutSinkPtr () -> std::shared_ptr< spdlog::sinks::stdout_sink< Mutex >>
 Create a standard output sink shared pointer and return it. The macros createStdoutSinkStPtr and createStdoutSinkMtPtr exist to improve readability and clarity of intent when calling this function. More...
 
template<typename Mutex >
auto KDSPDSetup::details::createStderrSinkPtr () -> std::shared_ptr< spdlog::sinks::stderr_sink< Mutex >>
 
template<typename Mutex >
auto KDSPDSetup::details::createStdoutColorSinkPtr () -> std::shared_ptr< spdlog::sinks::ansicolor_stdout_sink< Mutex >>
 Create an color standard output sink shared pointer and return it. The macros createStdoutColorSinkStPtr and createStdoutColorSinkMtPtr exist to improve readability and clarity of intent when calling this function. On Windows, the sink is a wincolor_stdout_sink, while on other platforms, it is an ansicolor_stdout_sink. More...
 
template<typename Mutex >
auto KDSPDSetup::details::createStderrColorSinkPtr () -> std::shared_ptr< spdlog::sinks::ansicolor_stderr_sink< Mutex >>
 
auto KDSPDSetup::details::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 argument based on the value of typeStr. Uses macros createFileSinkStPtr and createFileSinkMtPtr for clarity. This function is called by KDSPDSetup::setup::handleTruncatableSink. More...
 
auto KDSPDSetup::details::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 argument based on the value of typeStr. Uses macros createRotatingFileSinkStPtr and createRotatingFileSinkMtPtr for clarity. This function is called by KDSPDSetup::setup::handleMultipleFileSink. More...
 
auto KDSPDSetup::details::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 argument based on the value of typeStr. Uses macros createDailyFileSinkStPtr and createDailyFileSinkMtPtr for clarity. This function is called by KDSPDSetup::setup::handleMultipleFileSink. More...
 
auto KDSPDSetup::details::genFromNullOrStdStr (toml::string &&typeStr) -> spdlog::sink_ptr
 Return the result of calling KDSPDSetup::details::createStdoutSinkPtr with the correct template argument or KDSPDSetup::details::createNullSinkPtr, based on the value of typeStr. Uses macros createStdoutSinkStPtr and createStdoutSinkMtPtr for clarity. This function is called by KDSPDSetup::setup::setupSink. More...
 

Variables

static auto const KDSPDSetup::details::stdStrs
 Vector of strings of spdlog standard output sink typenames. Used when matching a type string from a TOML table to determine what additional type-specific fields should be read from the table. More...
 
static auto const KDSPDSetup::details::fileStrs { std::vector<std::string>{ "basic_file_sink_st", "basic_file_sink_mt" } }
 Vector of strings of spdlog basic file sink typenames. Used when matching a type string from a TOML table to determine what additional type-specific fields should be read from the table. More...
 
static auto const KDSPDSetup::details::rotateStrs { std::vector<std::string>{ "rotating_file_sink_st", "rotating_file_sink_mt" } }
 Vector of strings of spdlog rotating file sink typenames. Used when matching a type string from a TOML table to determine what additional type-specific fields should be read from the table. More...
 
static auto const KDSPDSetup::details::dailyStrs { std::vector<std::string>{ "daily_file_sink_st", "daily_file_sink_mt" } }
 Vector of strings of spdlog daily file sink typenames. Used when matching a type string from a TOML table to determine what additional type-specific fields should be read from the table. More...
 
static auto const KDSPDSetup::details::nullStrs { std::vector<std::string>{ "null_sink_st", "null_sink_mt" } }
 Vector of strings of spdlog null sink typenames. Used when matching a type string from a TOML table to determine what additional type-specific fields should be read from the table. More...
 
static auto const KDSPDSetup::details::linuxStrs { std::vector<std::string>{ "syslog_sink_st", "syslog_sink_mt" } }
 Vector of strings of spdlog syslog sink typenames. Used when matching a type string from a TOML table to determine what additional type-specific fields should be read from the table. More...
 
static auto const KDSPDSetup::details::winStrs { std::vector<std::string>{ "msvc_sink_st", "msvc_sink_mt" } }
 Vector of strings of spdlog MSVC sink typenames. Used when matching a type string from a TOML table to determine what additional type-specific fields should be read from the table. More...
 
static auto const KDSPDSetup::details::levelMap
 A simple map associating strings of spdlog::level::level_enum names to the enums themselves. Used to pass an enum to spdlog::logger::set_level given a string read from a TOML table. More...
 
static auto const KDSPDSetup::details::overflowMap
 A simple map associating strings of spdlog::async_overflow_policy names to the enums themselves. Used to pass an overflow policy to the constructor for an async logger given a string either read from a TOML table or set to the default "block". More...
 

Macro Definition Documentation

◆ createDailyFileSinkMtPtr

#define createDailyFileSinkMtPtr   createDailyFileSinkPtr<std::mutex>

A macro alias to improve readability of calls to KDSPDSetup::details::createDailyFileSinkPtr.

Definition at line 256 of file details.h.

◆ createDailyFileSinkStPtr

#define createDailyFileSinkStPtr   createDailyFileSinkPtr<spdlog::details::null_mutex>

A macro alias to improve readability of calls to KDSPDSetup::details::createDailyFileSinkPtr.

Definition at line 250 of file details.h.

◆ createFileSinkMtPtr

#define createFileSinkMtPtr   createFileSinkPtr<std::mutex>

A macro alias to improve readability of calls to KDSPDSetup::details::createFileSinkPtr.

Definition at line 244 of file details.h.

◆ createFileSinkStPtr

#define createFileSinkStPtr   createFileSinkPtr<spdlog::details::null_mutex>

A macro alias to improve readability of calls to KDSPDSetup::details::createFileSinkPtr.

Definition at line 238 of file details.h.

◆ createRotatingFileSinkMtPtr

#define createRotatingFileSinkMtPtr   createRotatingFileSinkPtr<std::mutex>

A macro alias to improve readability of calls to KDSPDSetup::details::createRotatingFileSinkPtr.

Definition at line 232 of file details.h.

◆ createRotatingFileSinkStPtr

#define createRotatingFileSinkStPtr   createRotatingFileSinkPtr<spdlog::details::null_mutex>

A macro alias to improve readability of calls to KDSPDSetup::details::createRotatingFileSinkPtr.

Definition at line 226 of file details.h.

◆ createStderrColorSinkMtPtr

#define createStderrColorSinkMtPtr   createStderrColorSinkPtr<spdlog::details::console_mutex>

Definition at line 286 of file details.h.

◆ createStderrColorSinkStPtr

#define createStderrColorSinkStPtr   createStderrColorSinkPtr<spdlog::details::console_nullmutex>

Definition at line 285 of file details.h.

◆ createStderrSinkMtPtr

#define createStderrSinkMtPtr   createStderrSinkPtr<spdlog::details::console_mutex>

Definition at line 271 of file details.h.

◆ createStderrSinkStPtr

#define createStderrSinkStPtr   createStderrSinkPtr<spdlog::details::console_nullmutex>

Definition at line 270 of file details.h.

◆ createStdoutColorSinkMtPtr

#define createStdoutColorSinkMtPtr   createStdoutColorSinkPtr<spdlog::details::console_mutex>

A macro alias to improve readability of calls to KDSPDSetup::details::createStdoutColorSinkPtr.

Definition at line 283 of file details.h.

◆ createStdoutColorSinkStPtr

#define createStdoutColorSinkStPtr   createStdoutColorSinkPtr<spdlog::details::console_nullmutex>

A macro alias to improve readability of calls to KDSPDSetup::details::createStdoutColorSinkPtr.

Definition at line 277 of file details.h.

◆ createStdoutSinkMtPtr

#define createStdoutSinkMtPtr   createStdoutSinkPtr<spdlog::details::console_mutex>

A macro alias to improve readability of calls to KDSPDSetup::details::createStdoutSinkPtr.

Definition at line 268 of file details.h.

◆ createStdoutSinkStPtr

#define createStdoutSinkStPtr   createStdoutSinkPtr<spdlog::details::console_nullmutex>

A macro alias to improve readability of calls to KDSPDSetup::details::createStdoutSinkPtr.

Definition at line 262 of file details.h.