From 39c6eb752a1c3541629ed6c8df9b9e94e27d6cde Mon Sep 17 00:00:00 2001 From: gabime Date: Sat, 7 Jul 2018 13:22:43 +0300 Subject: [PATCH] Code formatting --- bench/bench.cpp | 6 +++--- example/example.cpp | 16 +--------------- include/spdlog/details/fmt_helper.h | 2 +- include/spdlog/sinks/basic_file_sink.h | 2 -- include/spdlog/sinks/dist_sink.h | 3 +-- include/spdlog/sinks/sink.h | 23 +++++++++++------------ tests/includes.h | 2 +- 7 files changed, 18 insertions(+), 36 deletions(-) diff --git a/bench/bench.cpp b/bench/bench.cpp index b1275f20..ec2b91e4 100644 --- a/bench/bench.cpp +++ b/bench/bench.cpp @@ -7,10 +7,10 @@ // bench.cpp : spdlog benchmarks // #include "spdlog/async.h" +#include "spdlog/sinks/basic_file_sink.h" #include "spdlog/sinks/daily_file_sink.h" #include "spdlog/sinks/null_sink.h" #include "spdlog/sinks/rotating_file_sink.h" -#include "spdlog/sinks/basic_file_sink.h" #include "spdlog/spdlog.h" #include "utils.h" #include @@ -122,7 +122,7 @@ void bench_mt(int howmany, std::shared_ptr log, int thread_count for (int t = 0; t < thread_count; ++t) { threads.push_back(std::thread([&]() { - for (int j = 0; j < howmany/thread_count; j++) + for (int j = 0; j < howmany / thread_count; j++) { log->info("Hello logger: msg number {}", j); } @@ -134,7 +134,7 @@ void bench_mt(int howmany, std::shared_ptr log, int thread_count t.join(); }; - auto delta = high_resolution_clock::now() - start; + auto delta = high_resolution_clock::now() - start; auto delta_d = duration_cast>(delta).count(); cout << "Elapsed: " << delta_d << "\t" << format(int(howmany / delta_d)) << "/sec" << endl; } diff --git a/example/example.cpp b/example/example.cpp index a9d8a7b0..eb520a25 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -7,7 +7,6 @@ // // - #include void stdout_example(); @@ -42,7 +41,6 @@ int main(int, char *[]) // custom error handler err_handler_example(); - // apply some function on all registered loggers spdlog::apply_all([&](std::shared_ptr l) { l->info("End of example."); }); @@ -57,7 +55,6 @@ int main(int, char *[]) } } - #include "spdlog/sinks/stdout_color_sinks.h" // or "/sinks/stdout_sinks.h" if no colors needed void stdout_example() @@ -68,7 +65,7 @@ void stdout_example() console->error("Some error message with arg: {}", 1); auto err_logger = spdlog::stderr_color_mt("error_logger"); - err_logger ->error("Some error message"); + err_logger->error("Some error message"); // Formatting examples console->warn("Easy padding in numbers like {:08d}", 12); console->critical("Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}", 42); @@ -84,21 +81,16 @@ void stdout_example() console->set_level(spdlog::level::trace); // Set specific logger's log level console->debug("This message should be displayed.."); - // Customize msg format for all loggers spdlog::set_pattern("[%H:%M:%S %z] [%^---%L---%$] [thread %t] %v"); console->info("This an info message with custom format"); - - // Compile time log levels // define SPDLOG_DEBUG_ON or SPDLOG_TRACE_ON SPDLOG_TRACE(console, "Enabled only #ifdef SPDLOG_TRACE_ON..{} ,{}", 1, 3.23); SPDLOG_DEBUG(console, "Enabled only #ifdef SPDLOG_DEBUG_ON.. {} ,{}", 1, 3.23); - } - #include "spdlog/sinks/basic_file_sink.h" void basic_example() { @@ -118,10 +110,8 @@ void daily_example() { // Create a daily logger - a new file is created every day on 2:30am auto daily_logger = spdlog::daily_logger_mt("daily_logger", "logs/daily.txt", 2, 30); - } - #include "spdlog/async.h" void async_example() { @@ -137,8 +127,6 @@ void async_example() } } - - // user defined types logging by implementing operator<< #include "spdlog/fmt/ostr.h" // must be included struct my_type @@ -151,7 +139,6 @@ struct my_type } }; - void user_defined_example() { spdlog::get("console")->info("user defined type: {}", my_type{14}); @@ -167,7 +154,6 @@ void err_handler_example() spdlog::get("console")->info("some invalid message to trigger an error {}{}{}{}", 3); } - // syslog example (linux/osx/freebsd) #ifndef _WIN32 #include "spdlog/sinks/syslog_sink.h" diff --git a/include/spdlog/details/fmt_helper.h b/include/spdlog/details/fmt_helper.h index f728b176..4fb0f3f5 100644 --- a/include/spdlog/details/fmt_helper.h +++ b/include/spdlog/details/fmt_helper.h @@ -122,7 +122,7 @@ inline void pad6(size_t n, fmt::memory_buffer &dest) dest.push_back('0'); dest.push_back('0'); dest.push_back('0'); - } + } append_int(n, dest); } diff --git a/include/spdlog/sinks/basic_file_sink.h b/include/spdlog/sinks/basic_file_sink.h index 59795401..ffa92be0 100644 --- a/include/spdlog/sinks/basic_file_sink.h +++ b/include/spdlog/sinks/basic_file_sink.h @@ -26,8 +26,6 @@ public: file_helper_.open(filename, truncate); } - - protected: void sink_it_(const details::log_msg &, const fmt::memory_buffer &formatted) override { diff --git a/include/spdlog/sinks/dist_sink.h b/include/spdlog/sinks/dist_sink.h index 152e45da..80861247 100644 --- a/include/spdlog/sinks/dist_sink.h +++ b/include/spdlog/sinks/dist_sink.h @@ -18,7 +18,7 @@ namespace spdlog { namespace sinks { -template +template class dist_sink : public sink { public: @@ -60,7 +60,6 @@ public: private: Mutex mutex_; std::vector> sinks_; - }; using dist_sink_mt = dist_sink; diff --git a/include/spdlog/sinks/sink.h b/include/spdlog/sinks/sink.h index 9f661908..c18e5781 100644 --- a/include/spdlog/sinks/sink.h +++ b/include/spdlog/sinks/sink.h @@ -18,17 +18,17 @@ public: : formatter_(std::unique_ptr(new pattern_formatter("%+"))) { } -// -// explicit sink(const std::string &formatter_pattern) -// : formatter_(std::unique_ptr(new pattern_formatter(formatter_pattern))) -// { -// } -// -// // sink with custom formatter -// explicit sink(std::unique_ptr sink_formatter) -// : formatter_(std::move(sink_formatter)) -// { -// } + // + // explicit sink(const std::string &formatter_pattern) + // : formatter_(std::unique_ptr(new pattern_formatter(formatter_pattern))) + // { + // } + // + // // sink with custom formatter + // explicit sink(std::unique_ptr sink_formatter) + // : formatter_(std::move(sink_formatter)) + // { + // } virtual ~sink() = default; @@ -60,7 +60,6 @@ public: formatter_ = std::move(sink_formatter); } - protected: level_t level_{level::trace}; std::unique_ptr formatter_; diff --git a/tests/includes.h b/tests/includes.h index 6a61bc06..c9056a02 100644 --- a/tests/includes.h +++ b/tests/includes.h @@ -13,10 +13,10 @@ #define SPDLOG_DEBUG_ON #include "spdlog/async.h" +#include "spdlog/sinks/basic_file_sink.h" #include "spdlog/sinks/daily_file_sink.h" #include "spdlog/sinks/null_sink.h" #include "spdlog/sinks/ostream_sink.h" #include "spdlog/sinks/rotating_file_sink.h" -#include "spdlog/sinks/basic_file_sink.h" #include "spdlog/sinks/stdout_color_sinks.h" #include "spdlog/spdlog.h"