mirror of
https://github.com/gabime/spdlog.git
synced 2025-09-28 17:19:34 +08:00
Added ANSI color sink.
This commit is contained in:
@@ -5,9 +5,12 @@
|
||||
//
|
||||
// spdlog usage example
|
||||
//
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "spdlog/sinks/ansicolor_sink.h"
|
||||
|
||||
#include <cstdlib> // EXIT_FAILURE
|
||||
#include <iostream>
|
||||
#include "spdlog/spdlog.h"
|
||||
#include <memory>
|
||||
|
||||
int main(int, char*[])
|
||||
{
|
||||
@@ -85,6 +88,27 @@ int main(int, char*[])
|
||||
syslog_logger->warn("This is warning that will end up in syslog. This is Linux only!");
|
||||
#endif
|
||||
|
||||
//
|
||||
// ANSI color logging (OS X and Linux. Windows only if ansi.sys is loaded.)
|
||||
//
|
||||
|
||||
// Create a sink to add colors to.
|
||||
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_logger->set_level(spd::level::trace);
|
||||
color_sink->setColor(spd::level::info, color_sink->bold + color_sink->green);
|
||||
color_logger->info("Testing color logger...");
|
||||
color_logger->trace("Trace");
|
||||
color_logger->debug("Debug");
|
||||
color_logger->info("Info");
|
||||
color_logger->notice("Notice");
|
||||
color_logger->warn("Warning");
|
||||
color_logger->error("Error");
|
||||
color_logger->critical("Critical");
|
||||
color_logger->alert("Alert");
|
||||
color_logger->emerg("Emergency");
|
||||
|
||||
//
|
||||
//Release and close all loggers
|
||||
//
|
||||
|
Reference in New Issue
Block a user