Add Logger
To further improve our outputs, e.g., structuring with different levels, using a Logger library might be an improvement.
I suggest replacing the debout
Macro with calls to spdlog
(https://github.com/gabime/spdlog) which is a header only library. It also allows easier formatting with fmt
(https://github.com/fmtlib/fmt, will become part of the standard in C++20).
#include <spdlog/spdlog.h>
void foo(){
SPDLOG_WARN("Warning");
}
int main(int, char**)
{
spdlog::set_pattern("%! in %s line %#: %v"); // For printing info which file and function.
spdlog::set_level(spdlog::level::info);
int a = 2;
SPDLOG_INFO("This is a test: a = {:04d}", a);
SPDLOG_ERROR("Error message");
SPDLOG_DEBUG("This is not getting printed as level is at info");
foo();
}
output:
main in main.cpp line 12: This is a test: a = 0002
main in main.cpp line 13: Error message
foo in main.cpp line 4: Warning