11#include "spdlog/sinks/basic_file_sink.h"
12#include "spdlog/sinks/stdout_color_sinks.h"
25#define C_BLACK "\033[0;30m"
26#define C_DARK_GRAY "\033[1;30m"
28#define C_RED "\033[0;31m"
29#define C_LIGHT_RED "\033[1;31m"
31#define C_GREEN "\033[0;32m"
32#define C_LIGHT_GREEN "\033[1;32m"
34#define C_ORANGE "\033[0;33m"
35#define C_YELLOW "\033[1;33m"
37#define C_BLUE "\033[0;34m"
38#define C_LIGHT_BLUE "\033[1;34m"
40#define C_PURPLE "\033[0;35m"
41#define C_LIGHT_PURPLE "\033[1;35m"
43#define C_CYAN "\033[0;36m"
44#define C_LIGHT_CYAN "\033[1;36m"
46#define C_LIGHT_GRAY "\033[0;37m"
47#define C_WHITE "\033[1;37m"
50[[maybe_unused]]
constexpr const char*
logPatternTrace =
"[%H:%M:%S.%e] [%^%L%$] [%s:%-3#] [%!()] %v";
52[[maybe_unused]]
constexpr const char*
logPatternDebug =
"[%H:%M:%S.%e] [%^%L%$] [%s:%-3#] %v";
54[[maybe_unused]]
constexpr const char*
logPatternInfo =
"[%H:%M:%S.%e] [%^%L%$] %v";
60 auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
65 case spdlog::level::trace:
66 #if LOG_LEVEL == LOG_LEVEL_DATA || LOG_LEVEL == LOG_LEVEL_TRACE
70 case spdlog::level::debug:
71 #if LOG_LEVEL == LOG_LEVEL_DEBUG
75 case spdlog::level::info:
76 case spdlog::level::warn:
77 case spdlog::level::err:
78 case spdlog::level::critical:
81 case spdlog::level::off:
82 case spdlog::level::n_levels:
88 auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(logpath,
true);
93 case spdlog::level::trace:
94#if LOG_LEVEL == LOG_LEVEL_DATA || LOG_LEVEL == LOG_LEVEL_TRACE
98 case spdlog::level::debug:
99#if LOG_LEVEL == LOG_LEVEL_DEBUG
103 case spdlog::level::info:
104 case spdlog::level::warn:
105 case spdlog::level::err:
106 case spdlog::level::critical:
109 case spdlog::level::off:
110 case spdlog::level::n_levels:
114 _ringBufferSink = std::make_shared<spdlog::sinks::ringbuffer_sink_mt>(4096);
118 std::shared_ptr<spdlog::sinks::dist_sink_mt> dist_filter_sink;
125 dist_filter_sink = std::make_shared<spdlog::sinks::dist_sink_mt>();
128 dist_filter_sink->add_sink(console_sink);
130 dist_filter_sink->add_sink(file_sink);
134 spdlog::set_default_logger(std::make_shared<spdlog::logger>(
"multi_sink", dist_filter_sink));
151 auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
152 console_sink->set_level(spdlog::level::trace);
155 spdlog::set_default_logger(std::make_shared<spdlog::logger>(
"console_sink", spdlog::sinks_init_list({ console_sink })));
158 spdlog::set_level(spdlog::level::level_enum::trace);
160 spdlog::flush_on(spdlog::level::trace);
163#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
165#elif SPDLOG_ACTIVE_LEVEL == SPDLOG_LEVEL_DEBUG
178 spdlog::default_logger()->flush();
188 LOG_INFO(
"========================================================================");
193 auto now = std::chrono::system_clock::now();
194 std::time_t now_c = std::chrono::system_clock::to_time_t(now);
195 [[maybe_unused]] tm* t = std::localtime(&now_c);
210 auto now = std::chrono::system_clock::now();
211 std::time_t now_c = std::chrono::system_clock::to_time_t(now);
212 [[maybe_unused]] tm* t = std::localtime(&now_c);
214 LOG_INFO(
"Program finished on {:04d}-{:02d}-{:02d}", 1900 + t->tm_year, 1 + t->tm_mon, t->tm_mday);
Config management for the Project.
constexpr const char * logPatternDebugColor
constexpr const char * logPatternDebug
constexpr const char * logPatternInfo
constexpr const char * logPatternTraceColor
constexpr const char * logPatternTrace
Utility class for logging to console and file.
#define LOG_INFO
Info to the user on the state of the program.
#define LOG_TRACE
Detailled info to trace the execution of the program. Should not be called on functions which receive...
Provides the version of the project.
#define PROJECT_VERSION_STRING
Project Version String in the form "major.minor.patch".
static const std::shared_ptr< spdlog::sinks::ringbuffer_sink_mt > & GetRingBufferSink()
Returns the ring buffer sink.
static void writeFooter() noexcept
Writes the logging footer.
static void writeHeader() noexcept
Writes the logging header.
static std::shared_ptr< spdlog::sinks::ringbuffer_sink_mt > _ringBufferSink
Ring buffer sink.
Logger()
Default constructor.
static void writeSeparator() noexcept
Writes a separation line to the console only.
Distribution sink with filter option. Stores a vector of sinks which get called when log is called.
const T & Get(const std::string &key, const T &&defaultValue)
Retrieves the value of a corresponding key from the configuration, if one exists.
bool HasKey(const std::string &key)
Checks if a corresponding key exists in the configuration.