From 487c3187887dd8cbaff710481b614b6fa0a172a8 Mon Sep 17 00:00:00 2001 From: gabime Date: Wed, 30 Mar 2016 19:34:40 +0300 Subject: [PATCH 1/6] ansicolor sink improvments (remove warning and uneeded string concat) --- include/spdlog/sinks/ansicolor_sink.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/spdlog/sinks/ansicolor_sink.h b/include/spdlog/sinks/ansicolor_sink.h index 0b79990b..a256f3b8 100644 --- a/include/spdlog/sinks/ansicolor_sink.h +++ b/include/spdlog/sinks/ansicolor_sink.h @@ -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); @@ -73,7 +73,7 @@ protected: std::map 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); } From ddc9aa8bdf779363919611b294624a004feec8ae Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Wed, 30 Mar 2016 19:43:59 +0300 Subject: [PATCH 2/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bc55968a..f2a155c1 100644 --- a/README.md +++ b/README.md @@ -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. From d405027fe97b70e67c126f250f683c9752cdae75 Mon Sep 17 00:00:00 2001 From: gabime Date: Wed, 30 Mar 2016 19:52:32 +0300 Subject: [PATCH 3/6] renamed setColor --- example/example.cpp | 2 +- include/spdlog/sinks/ansicolor_sink.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/example/example.cpp b/example/example.cpp index 378e8b8e..a6bcc3d1 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -113,7 +113,7 @@ void color_example() auto color_sink = std::make_shared(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"); diff --git a/include/spdlog/sinks/ansicolor_sink.h b/include/spdlog/sinks/ansicolor_sink.h index a256f3b8..2eaaa801 100644 --- a/include/spdlog/sinks/ansicolor_sink.h +++ b/include/spdlog/sinks/ansicolor_sink.h @@ -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 //@{ @@ -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; } From ccabe07f3fe70738199306c49efb3d355d768448 Mon Sep 17 00:00:00 2001 From: gabime Date: Wed, 30 Mar 2016 19:54:42 +0300 Subject: [PATCH 4/6] license --- include/spdlog/sinks/ansicolor_sink.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/spdlog/sinks/ansicolor_sink.h b/include/spdlog/sinks/ansicolor_sink.h index 2eaaa801..a1b8f0e8 100644 --- a/include/spdlog/sinks/ansicolor_sink.h +++ b/include/spdlog/sinks/ansicolor_sink.h @@ -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) // From bcc1918da1031dc807ae14590f9317b787e6fbf8 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Wed, 30 Mar 2016 19:55:44 +0300 Subject: [PATCH 5/6] Update README.md console color example --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index f2a155c1..da726132 100644 --- a/README.md +++ b/README.md @@ -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 + + //console color example + auto console_out = spdlog::sinks::stderr_sink_st::instance(); + auto color_sink = std::make_shared(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) { From 0d97696f784b37d38ea00a3e39459b2226efcb44 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Wed, 30 Mar 2016 19:56:37 +0300 Subject: [PATCH 6/6] Update README.md --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index da726132..de701532 100644 --- a/README.md +++ b/README.md @@ -134,12 +134,12 @@ int main(int, char* []) syslog_logger->warn("This is warning that will end up in syslog. This is Linux only!"); #endif - //console color example - auto console_out = spdlog::sinks::stderr_sink_st::instance(); - auto color_sink = std::make_shared(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..."); + //colored console sink example + auto console_out = spdlog::sinks::stderr_sink_st::instance(); + auto color_sink = std::make_shared(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) {