mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-25 10:01:33 +08:00
Merge branch 'master' of https://github.com/gabime/spdlog
This commit is contained in:
commit
e9633a5363
@ -22,7 +22,7 @@ Just copy the source [folder](https://github.com/gabime/spdlog/tree/master/inclu
|
||||
* Various log targets:
|
||||
* Rotating log files.
|
||||
* Daily log files.
|
||||
* Console logging.
|
||||
* Console logging (including colors).
|
||||
* Linux syslog.
|
||||
* Easily extendable with custom log targets (just implement a single function in the [sink](include/spdlog/sinks/sink.h) interface).
|
||||
* Severity based filtering - threshold levels can be modified in runtime as well as in compile time.
|
||||
@ -133,6 +133,13 @@ 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)
|
||||
{
|
||||
|
@ -113,7 +113,7 @@ void color_example()
|
||||
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_sink->set_color(spd::level::info, color_sink->bold + color_sink->green);
|
||||
color_logger->info("Testing color logger...");
|
||||
color_logger->trace("Trace");
|
||||
color_logger->debug("Debug");
|
||||
|
@ -1,5 +1,5 @@
|
||||
//
|
||||
// Copyright(c) 2016 Kevin M. Godby.
|
||||
// Copyright(c) 2016 Kevin M. Godby (modified version by spdlog).
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
|
||||
@ -21,7 +21,7 @@ namespace sinks {
|
||||
*/
|
||||
class ansicolor_sink : public sink {
|
||||
public:
|
||||
ansicolor_sink(sink_ptr sink);
|
||||
ansicolor_sink(sink_ptr wrapped_sink);
|
||||
virtual ~ansicolor_sink();
|
||||
|
||||
ansicolor_sink(const ansicolor_sink& other);
|
||||
@ -30,7 +30,7 @@ public:
|
||||
virtual void log(const details::log_msg& msg) override;
|
||||
virtual void flush() override;
|
||||
|
||||
void setColor(level::level_enum level, const std::string& color);
|
||||
void set_color(level::level_enum level, const std::string& color);
|
||||
|
||||
/// \name Formatting codes
|
||||
//@{
|
||||
@ -73,7 +73,7 @@ protected:
|
||||
std::map<level::level_enum, std::string> colors_;
|
||||
};
|
||||
|
||||
inline ansicolor_sink::ansicolor_sink(sink_ptr sink) : sink_(sink)
|
||||
inline ansicolor_sink::ansicolor_sink(sink_ptr wrapped_sink) : sink_(wrapped_sink)
|
||||
{
|
||||
colors_[level::trace] = white;
|
||||
colors_[level::debug] = white;
|
||||
@ -115,7 +115,7 @@ inline void ansicolor_sink::log(const details::log_msg& msg)
|
||||
const std::string s = msg.formatted.str();
|
||||
const std::string suffix = reset;
|
||||
details::log_msg m;
|
||||
m.formatted.write(prefix + s + suffix);
|
||||
m.formatted << prefix << s << suffix;
|
||||
sink_->log(m);
|
||||
}
|
||||
|
||||
@ -124,7 +124,7 @@ inline void ansicolor_sink::flush()
|
||||
sink_->flush();
|
||||
}
|
||||
|
||||
inline void ansicolor_sink::setColor(level::level_enum level, const std::string& color)
|
||||
inline void ansicolor_sink::set_color(level::level_enum level, const std::string& color)
|
||||
{
|
||||
colors_[level] = color;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user