API for color support in console logger

This commit is contained in:
gabime
2016-04-03 01:38:49 +03:00
parent a96092ac32
commit 296623baa3
6 changed files with 46 additions and 96 deletions

View File

@@ -65,8 +65,8 @@ int main(int, char* [])
namespace spd = spdlog;
try
{
//Create console, multithreaded logger
auto console = spd::stdout_logger_mt("console");
//Create thread safe console logger (with colors)
auto console = spd::stdout_logger_mt("console", true);
console->info("Welcome to spdlog!") ;
console->info("An info message example {}..", 1);
console->info() << "Streams are supported too " << 1;
@@ -133,13 +133,7 @@ int main(int, char* [])
auto syslog_logger = spd::syslog_logger("syslog", ident, LOG_PID);
syslog_logger->warn("This is warning that will end up in syslog. This is Linux only!");
#endif
//colored console sink example
auto console_out = spdlog::sinks::stderr_sink_st::instance();
auto color_sink = std::make_shared<spd::sinks::ansicolor_sink>(console_out); // wraps around another sink
auto color_logger = spd::details::registry::instance().create("Color", color_sink);
color_sink->set_color(spd::level::info, color_sink->bold + color_sink->green);
color_logger->info("Testing color logger...");
}
catch (const spd::spdlog_ex& ex)
{