spdlog
spdlog copied to clipboard
color_sinks use fmtlib styled colors and emphasis instead of predefined string color ansicodes and support ansicode on windows
Hello contributors, I want to introduce fmtlib's color implementation into spdlog color_sinks and no need to rely on fmtlib source code and copied into spdlog's source. Converted necessary macros to spdlog's macro names and copied/edited needed functions and definitions. After that, we got more color and styling options with familiar syntax from fmtlib.
Usage
#define SPDLOG_WINDOWS_USE_ANSICOLOR // use ansicolors on windows (windows terminal etc.) instead of wincolor sink
#include "spdlog/spdlog.h"
#include "spdlog/sinks/stdout_color_sinks.h"
void stdout_example()
{
// create color multi threaded logger
auto console = spdlog::stdout_color_mt("console");
auto console_sink = static_cast<spdlog::sinks::stdout_color_sink_mt*>(console->sinks().at(0).get());
console_sink->set_style(spdlog::level::info, spdlog::fg(spdlog::color::cornflower_blue) | spdlog::bg(spdlog::color::white) |
spdlog::emphasis::bold | spdlog::emphasis::italic); // or custom rgb color -> spdlog::fg(spdlog::rgb(0, 0, 255))
spdlog::get("console")->info("loggers can be retrieved from a global registry using the spdlog::get(logger_name)");
}
Thanks for the pr. Is there a way to use fmt colors without copy its code? Id rather not add duplicate fmt’s code.
Thanks for the pr. Is there a way to use fmt colors without copy its code? Id rather not add duplicate fmt’s code.
Another way is using these ansicodes as literals. I can write another implementation but it'll be similar to this.
I will close this for now. Will reconsider if there is more demand for this. Thanks anyway!