From 4efbd950d6805b13478f8009ccbf8f67d403c3e7 Mon Sep 17 00:00:00 2001 From: gabime Date: Sat, 20 Aug 2016 13:55:50 +0300 Subject: [PATCH] atyle --- example/example.cpp | 11 +++++---- include/spdlog/details/registry.h | 12 +++++----- include/spdlog/details/spdlog_impl.h | 2 +- include/spdlog/spdlog.h | 4 ++-- tests/registry.cpp | 36 +++++++++++++++------------- 5 files changed, 36 insertions(+), 29 deletions(-) diff --git a/example/example.cpp b/example/example.cpp index 0e553a96..40844f62 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -78,11 +78,14 @@ int main(int, char*[]) // Change default log error handler err_handler_example(); - - // Apply a function on all registered loggers - spd::apply_all([&](std::shared_ptr l) {l->info("End of example."); }); - // Release and close all loggers + // Apply a function on all registered loggers + spd::apply_all([&](std::shared_ptr l) + { + l->info("End of example."); + }); + + // Release and close all loggers spdlog::drop_all(); } // Exceptions will only be thrown upon failed logger or sink construction (not during logging) diff --git a/include/spdlog/details/registry.h b/include/spdlog/details/registry.h index 4f5a0893..ee14adfd 100644 --- a/include/spdlog/details/registry.h +++ b/include/spdlog/details/registry.h @@ -71,12 +71,12 @@ public: return new_logger; } - void apply_all(std::function)> fun) - { - std::lock_guard lock(_mutex); - for (auto &l : _loggers) - fun(l.second); - } + void apply_all(std::function)> fun) + { + std::lock_guard lock(_mutex); + for (auto &l : _loggers) + fun(l.second); + } void drop(const std::string& logger_name) { diff --git a/include/spdlog/details/spdlog_impl.h b/include/spdlog/details/spdlog_impl.h index f179ac33..f3e5bf2a 100644 --- a/include/spdlog/details/spdlog_impl.h +++ b/include/spdlog/details/spdlog_impl.h @@ -165,7 +165,7 @@ inline void spdlog::set_sync_mode() inline void spdlog::apply_all(std::function)> fun) { - details::registry::instance().apply_all(fun); + details::registry::instance().apply_all(fun); } inline void spdlog::drop_all() diff --git a/include/spdlog/spdlog.h b/include/spdlog/spdlog.h index 82852de6..3370307c 100644 --- a/include/spdlog/spdlog.h +++ b/include/spdlog/spdlog.h @@ -113,7 +113,7 @@ std::shared_ptr create(const std::string& logger_name, const It& sinks_b // Create and register a logger with templated sink type -// Example: +// Example: // spdlog::create("mylog", "dailylog_filename", "txt"); template std::shared_ptr create(const std::string& logger_name, Args...); @@ -123,7 +123,7 @@ std::shared_ptr create(const std::string& logger_name, Args...); void register_logger(std::shared_ptr logger); // Apply a user defined function on all registered loggers -// Example: +// Example: // spdlog::apply_all([&](std::shared_ptr l) {l->flush();}); void apply_all(std::function)> fun); diff --git a/tests/registry.cpp b/tests/registry.cpp index cde61edb..1936932a 100644 --- a/tests/registry.cpp +++ b/tests/registry.cpp @@ -25,24 +25,28 @@ TEST_CASE("explicit register" "[registry]") TEST_CASE("apply_all" "[registry]") { - spdlog::drop_all(); - auto logger = std::make_shared(tested_logger_name, std::make_shared()); - spdlog::register_logger(logger); - auto logger2 = std::make_shared(tested_logger_name2, std::make_shared()); - spdlog::register_logger(logger2); + spdlog::drop_all(); + auto logger = std::make_shared(tested_logger_name, std::make_shared()); + spdlog::register_logger(logger); + auto logger2 = std::make_shared(tested_logger_name2, std::make_shared()); + spdlog::register_logger(logger2); - int counter = 0; - spdlog::apply_all([&counter](std::shared_ptr l){counter++;}); - REQUIRE(counter == 2); + int counter = 0; + spdlog::apply_all([&counter](std::shared_ptr l) + { + counter++; + }); + REQUIRE(counter == 2); - counter = 0; - spdlog::drop(tested_logger_name2); - spdlog::apply_all([&counter](std::shared_ptr l) - { - REQUIRE(l->name() == tested_logger_name); - counter++; } - ); - REQUIRE(counter == 1); + counter = 0; + spdlog::drop(tested_logger_name2); + spdlog::apply_all([&counter](std::shared_ptr l) + { + REQUIRE(l->name() == tested_logger_name); + counter++; + } + ); + REQUIRE(counter == 1); }