diff --git a/bench/bench.cpp b/bench/bench.cpp index 7ff5a570..b16f7f13 100644 --- a/bench/bench.cpp +++ b/bench/bench.cpp @@ -54,19 +54,18 @@ int main(int argc, char *argv[]) cout << "******************************************************************" "*************\n"; - - bench(howmany, spdlog::create("null_st")); - return 0; + bench(howmany, spdlog::create("null_st")); + return 0; auto rotating_st = spdlog::rotating_logger_st("rotating_st", "logs/rotating_st.log", file_size, rotating_files); bench(howmany, rotating_st); - return 0; + return 0; auto basic_st = spdlog::basic_logger_st("basic_st", "logs/basic_st.log", true); bench(howmany, basic_st); - //auto rotating_st = spdlog::rotating_logger_st("rotating_st", "logs/rotating_st.log", file_size, rotating_files); - //bench(howmany, rotating_st); + // auto rotating_st = spdlog::rotating_logger_st("rotating_st", "logs/rotating_st.log", file_size, rotating_files); + // bench(howmany, rotating_st); auto daily_st = spdlog::daily_logger_st("daily_st", "logs/daily_st.log"); bench(howmany, daily_st); diff --git a/example/example.cpp b/example/example.cpp index 370b5ff0..2108e45b 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -43,7 +43,7 @@ int main(int, char *[]) // log binary data binary_example(); - + // a logger can have multiple targets with different formats multi_sink_example(); @@ -169,12 +169,11 @@ void binary_example() auto console = spdlog::get("console"); std::array buf; console->info("Binary example: {}", spdlog::to_hex(buf)); - console->info("Another binary example:{:n}", spdlog::to_hex(std::begin(buf), std::begin(buf)+10)); + console->info("Another binary example:{:n}", spdlog::to_hex(std::begin(buf), std::begin(buf) + 10)); // more examples: // logger->info("uppercase: {:X}", spdlog::to_hex(buf)); // logger->info("uppercase, no delimiters: {:Xs}", spdlog::to_hex(buf)); // logger->info("uppercase, no delimiters, no position info: {:Xsp}", spdlog::to_hex(buf)); - } // create logger with 2 targets with different log levels and formats diff --git a/include/spdlog/fmt/bin_to_hex.h b/include/spdlog/fmt/bin_to_hex.h index a1b4eb9b..2c43ec2a 100644 --- a/include/spdlog/fmt/bin_to_hex.h +++ b/include/spdlog/fmt/bin_to_hex.h @@ -21,7 +21,6 @@ // char buf[128]; // logger->info("Some buffer {:X}", spdlog::to_hex(std::begin(buf), std::end(buf))); - namespace spdlog { namespace details { @@ -30,20 +29,27 @@ class bytes_range { public: bytes_range(It range_begin, It range_end) - : begin_(range_begin), end_(range_end) - {} + : begin_(range_begin) + , end_(range_end) + { + } - It begin() const {return begin_;} - It end() const {return end_;} + It begin() const + { + return begin_; + } + It end() const + { + return end_; + } private: It begin_, end_; - }; } // namespace details // create a bytes_range that wraps the given container -template +template inline details::bytes_range to_hex(const Container &container) { static_assert(sizeof(typename Container::value_type) == 1, "sizeof(Container::value_type) != 1"); @@ -58,7 +64,6 @@ inline details::bytes_range to_hex(const It range_begin, const It range_end) return details::bytes_range(range_begin, range_end); } - } // namespace spdlog namespace fmt { @@ -83,18 +88,18 @@ struct formatter> { switch (*it) { - case 'X': - use_uppercase = true; - break; - case 's': - put_delimiters = false; - break; - case 'p': - put_positions = false; - break; - case 'n': - put_newlines = false; - break; + case 'X': + use_uppercase = true; + break; + case 's': + put_delimiters = false; + break; + case 'p': + put_positions = false; + break; + case 'n': + put_newlines = false; + break; } ++it; @@ -114,7 +119,7 @@ struct formatter> std::size_t column = line_size; auto inserter = ctx.begin(); - for (auto &item:the_range) + for (auto &item : the_range) { auto ch = static_cast(item); pos++; @@ -126,7 +131,7 @@ struct formatter> // put first byte without delimiter in front of it *inserter++ = hex_chars[(ch >> 4) & 0x0f]; *inserter++ = hex_chars[ch & 0x0f]; - column+= 2; + column += 2; continue; } @@ -138,7 +143,7 @@ struct formatter> *inserter++ = hex_chars[(ch >> 4) & 0x0f]; *inserter++ = hex_chars[ch & 0x0f]; - column+= 2; + column += 2; } return inserter; } @@ -155,7 +160,7 @@ struct formatter> if (put_positions) { - fmt::format_to(inserter, "{:<04X}: ", pos-1); + fmt::format_to(inserter, "{:<04X}: ", pos - 1); return 7; } else diff --git a/tests/test_misc.cpp b/tests/test_misc.cpp index 2df0371d..22dfb4b8 100644 --- a/tests/test_misc.cpp +++ b/tests/test_misc.cpp @@ -135,8 +135,6 @@ TEST_CASE("clone async", "[clone]") spdlog::drop_all(); } - - #include "spdlog/fmt/bin_to_hex.h" TEST_CASE("to_hex", "[to_hex]") @@ -145,7 +143,7 @@ TEST_CASE("to_hex", "[to_hex]") auto oss_sink = std::make_shared(oss); spdlog::logger oss_logger("oss", oss_sink); - std::vector v {9, 0xa, 0xb, 0xc, 0xff, 0xff}; + std::vector v{9, 0xa, 0xb, 0xc, 0xff, 0xff}; oss_logger.info("{}", spdlog::to_hex(v)); auto output = oss.str(); @@ -158,7 +156,7 @@ TEST_CASE("to_hex_upper", "[to_hex]") auto oss_sink = std::make_shared(oss); spdlog::logger oss_logger("oss", oss_sink); - std::vector v {9, 0xa, 0xb, 0xc, 0xff, 0xff}; + std::vector v{9, 0xa, 0xb, 0xc, 0xff, 0xff}; oss_logger.info("{:X}", spdlog::to_hex(v)); auto output = oss.str(); @@ -171,7 +169,7 @@ TEST_CASE("to_hex_no_delimiter", "[to_hex]") auto oss_sink = std::make_shared(oss); spdlog::logger oss_logger("oss", oss_sink); - std::vector v {9, 0xa, 0xb, 0xc, 0xff, 0xff}; + std::vector v{9, 0xa, 0xb, 0xc, 0xff, 0xff}; oss_logger.info("{:sX}", spdlog::to_hex(v)); auto output = oss.str();