Logging API
The core C++ library offers an API for managing logging in the svs/core/logging.h
header.
Use of the logging API will supersede environment variable initialization (if applicable).
Logging Functions
-
template<typename ...Args>
void svs::logging::log(logger_ptr &logger, Level level, fmt::format_string<Args...> fmt, Args&&... args) Send a message to the logger at the given logging level.
Materialization of the logging message will be deferred until the level has been checked.
Convenience aliases at the corresponding log level include:
trace
,debug
,info
,warn
,error
,critical
.
-
template<typename ...Args>
void svs::logging::log(Level level, fmt::format_string<Args...> fmt, Args&&... args) Send a message to the global logger at the given logging level.
Materialization of the logging message will be deferred until the level has been checked.
Convenience aliases at the corresponding log level include:
trace
,debug
,info
,warn
,error
,critical
.
Extra Definitions
-
enum class svs::logging::Level
Enum controlling verbosity.
These definitions mirror those defined in “spdlog”
Values:
-
enumerator Trace
-
enumerator Debug
-
enumerator Info
-
enumerator Warn
-
enumerator Error
-
enumerator Critical
-
enumerator Off
-
enumerator Trace
-
using svs::logging::logger_ptr = std::shared_ptr<::spdlog::logger>
The type of the global logger.
-
using svs::logging::sink_ptr = std::shared_ptr<::spdlog::sinks::sink>
The type for sinks registered with loggers.
-
inline ::svs::lib::ReadWriteProtected<logger_ptr> &svs::logging::global_logger()
-
inline logger_ptr svs::logging::get()
Return a shared pointer to the current global logger.
This function is safe to call in a multi-threaded context.
-
inline void svs::logging::set(const logger_ptr &logger)
Override the currently configured logger.
This function is safe to call in a multi-threaded contex but it is the user’s responsibility to ensure that all sinks registered with the logger are multi-thread safe.
- Parameters:
logger – A shared pointer to any
spdlog::logger
.
-
inline void svs::logging::set(logger_ptr &&logger)
Override the currently configured logger.
This function is safe to call in a multi-threaded contex but it is the user’s responsibility to ensure that all sinks registered with the logger are multi-thread safe.
- Parameters:
logger – A shared pointer to any
spdlog::logger
.
Sinks
-
inline sink_ptr svs::logging::file_sink(const std::string &filename, bool truncate = true)
A sink writing logging message to a file.
This function uses
spdlog
to create and open the log file. As such,spdlog
will make the full path to the log file, creating intermediate directories as needed. If the process lacks sufficient permissions to create the path, then an exception is thrown at creation time.