KDSPDSetup
Small library to initialize spdlog loggers from a toml configuration file.
|
This namespace contains the functions directly called by KDSPDSetup::setupFrom, along with helpers called by those functions. The file which contains the definitions for members of KDSPDSetup::setup, setup.h, is included in the implementation file kdspdsetup.cpp The functions defined in this namespace make use of the members of namespace KDSPDSetup::details, defined in details.h. More...
Functions | |
void | handleMultipleFileSink (toml::string &&typeStr, toml::table &&sinkTable, spdlog::sink_ptr &sinkPtr, bool const &truncate) |
Helper function for setting up sinks that use multiple files. The function extracts values for base_filename and max_files from the given table, which are needed by the constructors of these types of sinks. Based on the type specified in typeStr, either KDSPDSetup::details::genFromRotateStr or KDSPDSetup::details::genFromDailyStr are invoked with these values. This function is called by KDSPDSetup::setup::handleTruncatableSink when typeStr specifies a rotating or daily file sink. More... | |
void | handleTruncatableSink (toml::string &&typeStr, toml::table &&sinkTable, spdlog::sink_ptr &sinkPtr) |
Helper function for setting up file-based sinks that require a truncate argument in their constructor. Further narrows down the type after determining value of truncate and calls either KDSPDSetup::details::genFromFileStr or KDSPDSetup::setup::handleMultipleFileSink. This function is invoked by KDSPDSetup::setup::setupSink. More... | |
void | setupSink (toml::table &&sinkTable) |
Given a table representation of a sink, creates an spdlog::sink_ptr , and evaluates the type of sink specified in the table. Based on the type, calls additional functions to parse type-specific fields and construct the sink with the correct constructor. Adds the resultant sink to KDSPDSetup::details::SPDMaps::mSinkMap, which is used to obtain sink pointers by name when constructing loggers. More... | |
void | setupSinks (toml::value const &data) |
Using data read from a toml file, extract vector of tables representing every sink specified. Call KDSPDSetup::setup::setupSink on each table in the vector to create an spdlog sink for each. These sinks are put into KDSPDSetup::details::SPDMaps::mSinkMap, which is later indexed when constructing loggers to obtain the named sink pointers. More... | |
void | setupPatterns (toml::value const &data) |
Using data read from a toml file, search for the key global_pattern . If it exists, use its string value as the global pattern for spdlog by passing it to spdlog::set_pattern . Search again for a table called pattern. If found, extract vector of tables representing every pattern specified. For each table in the vector, add the name and pattern format string specified to KDSPDSetup::details::SPDMaps::mPatternMap. This map is used when constructing loggers that will use non-global patterns to format messages, allowing indexing of format strings by name. More... | |
void | setupThreadPools (toml::value const &data) |
Using data read from a toml file, search for a table global_thread_pool , and initialize it with the specified queue size and thread count fields by calling spdlog::init_thread_pool . Search again for a table thread_pool . If found, extract vector of tables representing every threadpool specified. For each table in the vector, add the name, queue size, and thread count specified to KDSPDSetup::details::SPDMaps::mThreadPoolMap. This map is used to index threadpool information by name when constructing asynchronous loggers. More... | |
void | registerAsynchronousLogger (toml::table const &loggerTable, toml::string const &name, std::vector< spdlog::sink_ptr > const &sinkList, toml::string const &pattern) |
Creates an std::shared_ptr<spdlog::async_logger> initialized with name , the sink pointers in sinklist , a thread pool pointer, and an overflow policy. The thread pool pointer is constructed with values obtained by indexing KDSPDSetup::details::SPDMaps::mThreadPoolMap by the specified thread_pool name in loggerTable . If not specified, the thread pool is set to spdlog::thread_pool() . The overflow policy is searched for in loggerTable , and defaults to "block" if not found. The function also sets a formatting pattern if pattern is nonempty before registering the logger by calling spdlog::register_logger . More... | |
void | registerSynchronousLogger (toml::table const &loggerTable, toml::string const &name, std::vector< spdlog::sink_ptr > const &sinkList, toml::string const &pattern) |
Creates an std::shared_ptr<spdlog::logger> initialized with name and the sink pointers in sinklist , sets the logger's pattern if nonempty and level if specified in loggerTable , and registers the logger by calling spdlog::register_logger on the shared_ptr . More... | |
void | setupLogger (toml::table const &loggerTable) |
Given a table representation of a logger whose name is not already registered with spdlog, evaluates whether the logger's specified type is asynchronous or not, and calls either KDSPDSetup::setup::registerAsynchronousLogger or KDSPDSetup::setup::registerSynchronousLogger accordingly. These functions are called with loggerTable , the specified name, a list of sink pointers, and the specified pattern, if found. The list of sink pointers is obtained by indexing KDSPDSetup::details::SPDMaps::mSinkMap with names specified in a list in the loggerTable . More... | |
void | setupLoggers (toml::value const &data) |
Using data read from a toml file, extract vector of tables representing every logger specified. Call KDSPDSetup::setup::setupLogger on each table in the vector to create and register an spdlog logger for each. The loggers should then be available through spdlog::get . More... | |
This namespace contains the functions directly called by KDSPDSetup::setupFrom, along with helpers called by those functions. The file which contains the definitions for members of KDSPDSetup::setup, setup.h, is included in the implementation file kdspdsetup.cpp The functions defined in this namespace make use of the members of namespace KDSPDSetup::details, defined in details.h.
void KDSPDSetup::setup::handleMultipleFileSink | ( | toml::string && | typeStr, |
toml::table && | sinkTable, | ||
spdlog::sink_ptr & | sinkPtr, | ||
bool const & | truncate | ||
) |
Helper function for setting up sinks that use multiple files. The function extracts values for base_filename
and max_files
from the given table, which are needed by the constructors of these types of sinks. Based on the type specified in typeStr, either KDSPDSetup::details::genFromRotateStr or KDSPDSetup::details::genFromDailyStr are invoked with these values. This function is called by KDSPDSetup::setup::handleTruncatableSink when typeStr
specifies a rotating or daily file sink.
typeStr | String of the sink's type, which is checked against string vectors in KDSPDSetup::details |
sinkTable | toml11 table representation for a particular sink specified in a configuration file. |
sinkPtr | An uninitialized sink pointer, which will be passed to functions that construct a sink. This pointer is eventually put into KDSPDSetup::details::SPDMaps::mSinkMap at the bottom of KDSPDSetup::setup::setupSink. |
truncate | The value for truncate obtained in caller KDSPDSetup::setup::handleTruncatableSink. |
Definition at line 18 of file setup.cpp.
void KDSPDSetup::setup::handleTruncatableSink | ( | toml::string && | typeStr, |
toml::table && | sinkTable, | ||
spdlog::sink_ptr & | sinkPtr | ||
) |
Helper function for setting up file-based sinks that require a truncate
argument in their constructor. Further narrows down the type after determining value of truncate
and calls either KDSPDSetup::details::genFromFileStr or KDSPDSetup::setup::handleMultipleFileSink. This function is invoked by KDSPDSetup::setup::setupSink.
typeStr | String of the sink's type, which is checked against string vectors in KDSPDSetup::details |
sinkTable | toml11 table representation for a particular sink specified in a configuration file. |
sinkPtr | An uninitialized sink pointer, which will be passed to functions that construct a sink. This pointer is eventually put into KDSPDSetup::details::SPDMaps::mSinkMap at the bottom of KDSPDSetup::setup::setupSink. |
Definition at line 32 of file setup.cpp.
void KDSPDSetup::setup::registerAsynchronousLogger | ( | toml::table const & | loggerTable, |
toml::string const & | name, | ||
std::vector< spdlog::sink_ptr > const & | sinkList, | ||
toml::string const & | pattern | ||
) |
Creates an std::shared_ptr<spdlog::async_logger>
initialized with name
, the sink pointers in sinklist
, a thread pool pointer, and an overflow policy. The thread pool pointer is constructed with values obtained by indexing KDSPDSetup::details::SPDMaps::mThreadPoolMap by the specified thread_pool
name in loggerTable
. If not specified, the thread pool is set to spdlog::thread_pool()
. The overflow policy is searched for in loggerTable
, and defaults to "block"
if not found. The function also sets a formatting pattern if pattern
is nonempty before registering the logger by calling spdlog::register_logger
.
loggerTable | toml11 table representation for a particular logger specified in a configuration file. |
name | A string with the name of the logger. This name is used to construct the logger and access it with spdlog::get . |
sinkList | A vector of spdlog::sink_ptr objects to use as the sinks for the logger. |
pattern | The format string for messages the logger will output. If empty, the logger uses the global pattern set up earlier in KDSPDSetup::setup::setupPatterns, or spdlog's default pattern if the global pattern was not created. |
Definition at line 150 of file setup.cpp.
void KDSPDSetup::setup::registerSynchronousLogger | ( | toml::table const & | loggerTable, |
toml::string const & | name, | ||
std::vector< spdlog::sink_ptr > const & | sinkList, | ||
toml::string const & | pattern | ||
) |
Creates an std::shared_ptr<spdlog::logger>
initialized with name
and the sink pointers in sinklist
, sets the logger's pattern
if nonempty and level
if specified in loggerTable
, and registers the logger by calling spdlog::register_logger
on the shared_ptr
.
loggerTable | toml11 table representation for a particular logger specified in a configuration file. |
name | A string with the name of the logger. This name is used to construct the logger and access it with spdlog::get . |
sinkList | A vector of spdlog::sink_ptr objects to use as the sinks for the logger. |
pattern | The format string for messages the logger will output. If empty, the logger uses the global pattern set up earlier in KDSPDSetup::setup::setupPatterns, or spdlog's default pattern if the global pattern was not created. |
Definition at line 185 of file setup.cpp.
void KDSPDSetup::setup::setupLogger | ( | toml::table const & | loggerTable | ) |
Given a table representation of a logger whose name is not already registered with spdlog, evaluates whether the logger's specified type is asynchronous or not, and calls either KDSPDSetup::setup::registerAsynchronousLogger or KDSPDSetup::setup::registerSynchronousLogger accordingly. These functions are called with loggerTable
, the specified name, a list of sink pointers, and the specified pattern, if found. The list of sink pointers is obtained by indexing KDSPDSetup::details::SPDMaps::mSinkMap with names specified in a list in the loggerTable
.
loggerTable | toml11 table representation for a particular logger specified in a configuration file. Passed in by KDSPDSetup::setup::setupLoggers. |
Definition at line 205 of file setup.cpp.
void KDSPDSetup::setup::setupLoggers | ( | toml::value const & | data | ) |
Using data read from a toml file, extract vector of tables representing every logger specified. Call KDSPDSetup::setup::setupLogger on each table in the vector to create and register an spdlog logger for each. The loggers should then be available through spdlog::get
.
data | toml11 representation of the configuration file. |
Definition at line 243 of file setup.cpp.
void KDSPDSetup::setup::setupPatterns | ( | toml::value const & | data | ) |
Using data read from a toml file, search for the key global_pattern
. If it exists, use its string value as the global pattern for spdlog by passing it to spdlog::set_pattern
. Search again for a table called pattern. If found, extract vector of tables representing every pattern specified. For each table in the vector, add the name and pattern format string specified to KDSPDSetup::details::SPDMaps::mPatternMap. This map is used when constructing loggers that will use non-global patterns to format messages, allowing indexing of format strings by name.
data | toml11 representation of the configuration file. |
Definition at line 108 of file setup.cpp.
void KDSPDSetup::setup::setupSink | ( | toml::table && | sinkTable | ) |
Given a table representation of a sink, creates an spdlog::sink_ptr
, and evaluates the type of sink specified in the table. Based on the type, calls additional functions to parse type-specific fields and construct the sink with the correct constructor. Adds the resultant sink to KDSPDSetup::details::SPDMaps::mSinkMap, which is used to obtain sink pointers by name when constructing loggers.
sinkTable | toml11 table representation for a particular sink specified in a configuration file. Passed in by KDSPDSetup::setup::setupSinks. |
Definition at line 43 of file setup.cpp.
void KDSPDSetup::setup::setupSinks | ( | toml::value const & | data | ) |
Using data read from a toml file, extract vector of tables representing every sink specified. Call KDSPDSetup::setup::setupSink on each table in the vector to create an spdlog sink for each. These sinks are put into KDSPDSetup::details::SPDMaps::mSinkMap, which is later indexed when constructing loggers to obtain the named sink pointers.
data | toml11 representation of the configuration file. |
Definition at line 99 of file setup.cpp.
void KDSPDSetup::setup::setupThreadPools | ( | toml::value const & | data | ) |
Using data read from a toml file, search for a table global_thread_pool
, and initialize it with the specified queue size and thread count fields by calling spdlog::init_thread_pool
. Search again for a table thread_pool
. If found, extract vector of tables representing every threadpool specified. For each table in the vector, add the name, queue size, and thread count specified to KDSPDSetup::details::SPDMaps::mThreadPoolMap. This map is used to index threadpool information by name when constructing asynchronous loggers.
data | toml11 representation of the configuration file. |
Definition at line 127 of file setup.cpp.