Back to C++20 standard!
Logging is worked (AdcOstreamLogger and AdcSPDLOGLogger classes)
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <mutex>
|
||||
#include <ranges>
|
||||
#include <regex>
|
||||
#include <thread>
|
||||
#include <utility>
|
||||
|
||||
#include "../common/adc_traits.h"
|
||||
@@ -453,6 +454,7 @@ namespace constants
|
||||
{
|
||||
|
||||
static constexpr char DEFAULT_CONVERTER_DELIMITER[] = " ";
|
||||
static constexpr char DEFAULT_CONVERTER_DELIMITER_COMA[] = ", ";
|
||||
|
||||
} // namespace constants
|
||||
|
||||
@@ -676,6 +678,17 @@ static constexpr size_t AdcFNV1aHash(const R& r)
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
||||
/* current thread ID std::string representation */
|
||||
|
||||
static std::string AdcThisThreadId()
|
||||
{
|
||||
std::stringstream st;
|
||||
st << std::this_thread::get_id();
|
||||
|
||||
return st.str();
|
||||
}
|
||||
|
||||
/* std::basic_ostream based multithread-safe simple logger */
|
||||
|
||||
template <typename CharT = char, typename CharTraitsT = std::char_traits<CharT>>
|
||||
@@ -709,43 +722,37 @@ public:
|
||||
return _currentLogLevel;
|
||||
}
|
||||
|
||||
template <traits::formattable... Ts>
|
||||
void logMessage(loglevel_t level, std::string_view fmt, Ts&&... args)
|
||||
void logMessage(loglevel_t level, const std::string& msg)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_logMutex);
|
||||
|
||||
if (_currentLogLevel < level)
|
||||
return;
|
||||
|
||||
std::string s;
|
||||
std::format_to(std::back_inserter(s), fmt, std::forward<Ts>(args)...);
|
||||
|
||||
const std::time_t now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
|
||||
|
||||
// format log-message in form:
|
||||
// [YYYY-MM-DD HH:MM:SS][level] log-message
|
||||
//
|
||||
_logStream << std::put_time(std::localtime(&now), "[%F %T]") << "[" << LOGLEVEL_MARK[_currentLogLevel] << "] "
|
||||
<< s;
|
||||
_logStream << std::put_time(std::localtime(&now), "[%F %T]") << "[" << LOGLEVEL_MARK[level] << "] " << msg
|
||||
<< "\n"
|
||||
<< std::flush;
|
||||
}
|
||||
|
||||
|
||||
template <traits::formattable... Ts>
|
||||
void logError(std::string_view fmt, Ts&&... args)
|
||||
void logError(const std::string& msg)
|
||||
{
|
||||
logMessage(ERROR_LEVEL, fmt, std::forward<Ts>(args)...);
|
||||
logMessage(ERROR_LEVEL, msg);
|
||||
}
|
||||
|
||||
template <traits::formattable... Ts>
|
||||
void logInfo(std::string_view fmt, Ts&&... args)
|
||||
void logInfo(const std::string& msg)
|
||||
{
|
||||
logMessage(INFO_LEVEL, fmt, std::forward<Ts>(args)...);
|
||||
logMessage(INFO_LEVEL, msg);
|
||||
}
|
||||
|
||||
template <traits::formattable... Ts>
|
||||
void logDebug(std::string_view fmt, Ts&&... args)
|
||||
void logDebug(const std::string& msg)
|
||||
{
|
||||
logMessage(DEBUG_LEVEL, fmt, std::forward<Ts>(args)...);
|
||||
logMessage(DEBUG_LEVEL, msg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user