stabilized logger classes

This commit is contained in:
Sascha Kühl
2026-02-04 14:45:26 +01:00
parent e7e66f44e2
commit 520b2bab49
10 changed files with 112 additions and 135 deletions
+11 -16
View File
@@ -9,7 +9,6 @@
#include <mutex>
namespace matador::logger {
/**
* @brief logger to write log messages to log domains
*
@@ -31,9 +30,9 @@ namespace matador::logger {
* All log messages are written through the internal
* log_domain object to the sinks.
*/
class logger final
{
class logger final {
public:
static constexpr size_t buffer_size = 16384;
/**
* Create a logger with a given source name connected
@@ -69,7 +68,7 @@ public:
* @param args The arguments to be replaced in the message
*/
template<typename ... ARGS>
void fatal(const char *what, ARGS const &... args) const { log(log_level::LVL_FATAL, what, args...); }
void fatal(const char *what, ARGS const &... args) const { log(log_level::Fatal, what, args...); }
/**
* Writes a log message string with log level LVL_FATAL
@@ -91,7 +90,7 @@ public:
* @param args The arguments to be replaced in the message
*/
template<typename ... ARGS>
void error(const char *what, ARGS const &... args) const { log(log_level::LVL_ERROR, what, args...); }
void error(const char *what, ARGS const &... args) const { log(log_level::Error, what, args...); }
/**
* Writes a log message string with log level LVL_FATAL
@@ -113,7 +112,7 @@ public:
* @param args The arguments to be replaced in the message
*/
template<typename ... ARGS>
void warn(const char *what, ARGS const &... args) const { log(log_level::LVL_WARN, what, args...); }
void warn(const char *what, ARGS const &... args) const { log(log_level::Warn, what, args...); }
/**
* Writes a log message string with log level LVL_FATAL
@@ -135,7 +134,7 @@ public:
* @param args The arguments to be replaced in the message
*/
template<typename ... ARGS>
void info(const char *what, ARGS const &... args) const { log(log_level::LVL_INFO, what, args...); }
void info(const char *what, ARGS const &... args) const { log(log_level::Info, what, args...); }
/**
* Writes a log message string with log level LVL_FATAL
@@ -157,7 +156,7 @@ public:
* @param args The arguments to be replaced in the message
*/
template<typename ... ARGS>
void debug(const char *what, ARGS const &... args) const { log(log_level::LVL_DEBUG, what, args...); }
void debug(const char *what, ARGS const &... args) const { log(log_level::Debug, what, args...); }
/**
* Writes a log message string with log level LVL_FATAL
@@ -179,7 +178,7 @@ public:
* @param args The arguments to be replaced in the message
*/
template<typename ... ARGS>
void trace(const char *what, ARGS const &... args) const { log(log_level::LVL_TRACE, what, args...); }
void trace(const char *what, ARGS const &... args) const { log(log_level::Trace, what, args...); }
/**
* Writes a log message represented by a char pointer
@@ -222,14 +221,10 @@ private:
};
template<typename... ARGS>
void logger::log(log_level lvl, const char *what, ARGS const &... args) const {
char message_buffer[16384];
void logger::log(const log_level lvl, const char *what, ARGS const &... args) const {
char message_buffer[buffer_size];
#ifdef _MSC_VER
sprintf_s(message_buffer, 16384, what, args...);
#else
sprintf(message_buffer, what, args...);
#endif
snprintf(message_buffer, buffer_size, what, args...);
logger_domain_->log(lvl, source_, message_buffer);
}