diff --git a/.clang-format b/.clang-format index 7e899319..b97f9282 100644 --- a/.clang-format +++ b/.clang-format @@ -6,7 +6,7 @@ Standard: c++17 IndentWidth: 4 TabWidth: 4 UseTab: Never -ColumnLimit: 120 +ColumnLimit: 130 AlignAfterOpenBracket: Align BinPackParameters: false AlignEscapedNewlines: Left diff --git a/CMakeLists.txt b/CMakeLists.txt index 278add93..95ba5236 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -287,8 +287,7 @@ if(NOT SPDLOG_USE_STD_FORMAT) target_link_libraries(spdlog PUBLIC fmt::fmt) endif() spdlog_enable_warnings(spdlog) -set_target_properties(spdlog PROPERTIES VERSION ${SPDLOG_VERSION} SOVERSION - ${SPDLOG_VERSION_MAJOR}.${SPDLOG_VERSION_MINOR}) +set_target_properties(spdlog PROPERTIES VERSION ${SPDLOG_VERSION} SOVERSION ${SPDLOG_VERSION_MAJOR}.${SPDLOG_VERSION_MINOR}) set_target_properties(spdlog PROPERTIES DEBUG_POSTFIX d) # set source groups for visual studio diff --git a/bench/async_bench.cpp b/bench/async_bench.cpp index 5e8ba05b..05cbe652 100644 --- a/bench/async_bench.cpp +++ b/bench/async_bench.cpp @@ -96,8 +96,8 @@ int main(int argc, char *argv[]) { for (int i = 0; i < iters; i++) { auto tp = std::make_shared(queue_size, 1); auto file_sink = std::make_shared(filename, true); - auto logger = std::make_shared("async_logger", std::move(file_sink), std::move(tp), - async_overflow_policy::block); + auto logger = + std::make_shared("async_logger", std::move(file_sink), std::move(tp), async_overflow_policy::block); bench_mt(howmany, std::move(logger), threads); // verify_file(filename, howmany); } diff --git a/bench/bench.cpp b/bench/bench.cpp index 9cde0db4..6538d7ef 100644 --- a/bench/bench.cpp +++ b/bench/bench.cpp @@ -38,8 +38,8 @@ static const int max_threads = 1000; void bench_threaded_logging(size_t threads, int iters) { spdlog::info("**************************************************************"); - spdlog::info(spdlog::fmt_lib::format(std::locale("en_US.UTF-8"), "Multi threaded: {:L} threads, {:L} messages", - threads, iters)); + spdlog::info( + spdlog::fmt_lib::format(std::locale("en_US.UTF-8"), "Multi threaded: {:L} threads, {:L} messages", threads, iters)); spdlog::info("**************************************************************"); auto basic_mt = spdlog::basic_logger_mt("basic_mt", "logs/basic_mt.log", true); @@ -121,8 +121,8 @@ void bench(int howmany, std::shared_ptr log) { auto delta = high_resolution_clock::now() - start; auto delta_d = duration_cast>(delta).count(); - spdlog::info(spdlog::fmt_lib::format(std::locale("en_US.UTF-8"), "{:<30} Elapsed: {:0.2f} secs {:>16L}/sec", - log->name(), delta_d, size_t(howmany / delta_d))); + spdlog::info(spdlog::fmt_lib::format(std::locale("en_US.UTF-8"), "{:<30} Elapsed: {:0.2f} secs {:>16L}/sec", log->name(), + delta_d, size_t(howmany / delta_d))); spdlog::drop(log->name()); } @@ -148,8 +148,8 @@ void bench_mt(int howmany, std::shared_ptr log, size_t thread_co auto delta = high_resolution_clock::now() - start; auto delta_d = duration_cast>(delta).count(); - spdlog::info(spdlog::fmt_lib::format(std::locale("en_US.UTF-8"), "{:<30} Elapsed: {:0.2f} secs {:>16L}/sec", - log->name(), delta_d, size_t(howmany / delta_d))); + spdlog::info(spdlog::fmt_lib::format(std::locale("en_US.UTF-8"), "{:<30} Elapsed: {:0.2f} secs {:>16L}/sec", log->name(), + delta_d, size_t(howmany / delta_d))); spdlog::drop(log->name()); } diff --git a/bench/latency.cpp b/bench/latency.cpp index d75ba3e9..08a7c418 100644 --- a/bench/latency.cpp +++ b/bench/latency.cpp @@ -91,8 +91,7 @@ int main(int argc, char *argv[]) { auto disabled_logger = std::make_shared("bench", std::make_shared()); disabled_logger->set_level(spdlog::level::off); benchmark::RegisterBenchmark("disabled-at-compile-time", bench_disabled_macro, disabled_logger); - benchmark::RegisterBenchmark("disabled-at-compile-time (global logger)", bench_disabled_macro_global_logger, - disabled_logger); + benchmark::RegisterBenchmark("disabled-at-compile-time (global logger)", bench_disabled_macro_global_logger, disabled_logger); benchmark::RegisterBenchmark("disabled-at-runtime", bench_logger, disabled_logger); benchmark::RegisterBenchmark("disabled-at-runtime (global logger)", bench_global_logger, disabled_logger); @@ -112,8 +111,7 @@ int main(int argc, char *argv[]) { spdlog::drop("basic_st"); // rotating st - auto rotating_st = - spdlog::rotating_logger_st("rotating_st", "latency_logs/rotating_st.log", file_size, rotating_files); + auto rotating_st = spdlog::rotating_logger_st("rotating_st", "latency_logs/rotating_st.log", file_size, rotating_files); benchmark::RegisterBenchmark("rotating_st", bench_logger, std::move(rotating_st))->UseRealTime(); spdlog::drop("rotating_st"); @@ -134,11 +132,8 @@ int main(int argc, char *argv[]) { spdlog::drop("basic_mt"); // rotating mt - auto rotating_mt = - spdlog::rotating_logger_mt("rotating_mt", "latency_logs/rotating_mt.log", file_size, rotating_files); - benchmark::RegisterBenchmark("rotating_mt", bench_logger, std::move(rotating_mt)) - ->Threads(n_threads) - ->UseRealTime(); + auto rotating_mt = spdlog::rotating_logger_mt("rotating_mt", "latency_logs/rotating_mt.log", file_size, rotating_files); + benchmark::RegisterBenchmark("rotating_mt", bench_logger, std::move(rotating_mt))->Threads(n_threads)->UseRealTime(); spdlog::drop("rotating_mt"); // daily mt @@ -150,8 +145,8 @@ int main(int argc, char *argv[]) { // async auto queue_size = 1024 * 1024 * 3; auto tp = std::make_shared(queue_size, 1); - auto async_logger = std::make_shared( - "async_logger", std::make_shared(), std::move(tp), spdlog::async_overflow_policy::overrun_oldest); + auto async_logger = std::make_shared("async_logger", std::make_shared(), std::move(tp), + spdlog::async_overflow_policy::overrun_oldest); benchmark::RegisterBenchmark("async_logger", bench_logger, async_logger)->Threads(n_threads)->UseRealTime(); benchmark::Initialize(&argc, argv); benchmark::RunSpecifiedBenchmarks(); diff --git a/example/example.cpp b/example/example.cpp index c4d01854..41843967 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -276,8 +276,7 @@ void user_defined_example() { spdlog::info("user defined type: {}", my_type(14)) // Custom error handler. Will be triggered on log failure. void err_handler_example() { // can be set globally or per logger(logger->set_error_handler(..)) - spdlog::set_error_handler( - [](const std::string &msg) { printf("*** Custom log error handler: %s ***\n", msg.c_str()); }); + spdlog::set_error_handler([](const std::string &msg) { printf("*** Custom log error handler: %s ***\n", msg.c_str()); }); } // syslog example (linux/osx/freebsd) diff --git a/include/spdlog/async.h b/include/spdlog/async.h index 64b8ae72..b4bdf6c9 100644 --- a/include/spdlog/async.h +++ b/include/spdlog/async.h @@ -48,8 +48,7 @@ struct async_factory_impl { } auto sink = std::make_shared(std::forward(args)...); - auto new_logger = - std::make_shared(std::move(logger_name), std::move(sink), std::move(tp), OverflowPolicy); + auto new_logger = std::make_shared(std::move(logger_name), std::move(sink), std::move(tp), OverflowPolicy); registry_inst.initialize_logger(new_logger); return new_logger; } diff --git a/include/spdlog/details/os.h b/include/spdlog/details/os.h index b17d8486..3b49487d 100644 --- a/include/spdlog/details/os.h +++ b/include/spdlog/details/os.h @@ -23,9 +23,9 @@ SPDLOG_API std::tm gmtime() noexcept; // eol definition #ifdef _WIN32 - constexpr static const char *default_eol = "\r\n"; +constexpr static const char *default_eol = "\r\n"; #else - constexpr static const char *default_eol = "\n"; +constexpr static const char *default_eol = "\n"; #endif // folder separator diff --git a/include/spdlog/details/udp_client-windows.h b/include/spdlog/details/udp_client-windows.h index 5cee2b48..8bae36b0 100644 --- a/include/spdlog/details/udp_client-windows.h +++ b/include/spdlog/details/udp_client-windows.h @@ -75,8 +75,8 @@ public: } int option_value = TX_BUFFER_SIZE; - if (::setsockopt(socket_, SOL_SOCKET, SO_SNDBUF, reinterpret_cast(&option_value), - sizeof(option_value)) < 0) { + if (::setsockopt(socket_, SOL_SOCKET, SO_SNDBUF, reinterpret_cast(&option_value), sizeof(option_value)) < + 0) { int last_error = ::WSAGetLastError(); cleanup_(); throw_winsock_error_("error: setsockopt(SO_SNDBUF) Failed!", last_error); diff --git a/include/spdlog/details/udp_client.h b/include/spdlog/details/udp_client.h index d27c6c37..e0cc4432 100644 --- a/include/spdlog/details/udp_client.h +++ b/include/spdlog/details/udp_client.h @@ -46,8 +46,8 @@ public: } int option_value = TX_BUFFER_SIZE; - if (::setsockopt(socket_, SOL_SOCKET, SO_SNDBUF, reinterpret_cast(&option_value), - sizeof(option_value)) < 0) { + if (::setsockopt(socket_, SOL_SOCKET, SO_SNDBUF, reinterpret_cast(&option_value), sizeof(option_value)) < + 0) { cleanup_(); throw_spdlog_ex("error: setsockopt(SO_SNDBUF) Failed!"); } diff --git a/include/spdlog/fmt/bin_to_hex.h b/include/spdlog/fmt/bin_to_hex.h index 7574d976..a0660cd4 100644 --- a/include/spdlog/fmt/bin_to_hex.h +++ b/include/spdlog/fmt/bin_to_hex.h @@ -61,8 +61,7 @@ private: // create a dump_info that wraps the given container template -inline details::dump_info to_hex(const Container &container, - size_t size_per_line = 32) { +inline details::dump_info to_hex(const Container &container, size_t size_per_line = 32) { static_assert(sizeof(typename Container::value_type) == 1, "sizeof(Container::value_type) != 1"); using Iter = typename Container::const_iterator; return details::dump_info(std::begin(container), std::end(container), size_per_line); @@ -139,8 +138,7 @@ struct formatter, char> { // format the given bytes range as hex template - auto format(const spdlog::details::dump_info &the_range, FormatContext &ctx) const - -> decltype(ctx.out()) { + auto format(const spdlog::details::dump_info &the_range, FormatContext &ctx) const -> decltype(ctx.out()) { constexpr const char *hex_upper = "0123456789ABCDEF"; constexpr const char *hex_lower = "0123456789abcdef"; const char *hex_chars = use_uppercase ? hex_upper : hex_lower; diff --git a/include/spdlog/sinks/basic_file_sink.h b/include/spdlog/sinks/basic_file_sink.h index 8ac1d433..a30e1dfa 100644 --- a/include/spdlog/sinks/basic_file_sink.h +++ b/include/spdlog/sinks/basic_file_sink.h @@ -19,9 +19,7 @@ namespace sinks { template class basic_file_sink final : public base_sink { public: - explicit basic_file_sink(const filename_t &filename, - bool truncate = false, - const file_event_handlers &event_handlers = {}); + explicit basic_file_sink(const filename_t &filename, bool truncate = false, const file_event_handlers &event_handlers = {}); const filename_t &filename() const; protected: diff --git a/include/spdlog/sinks/daily_file_sink.h b/include/spdlog/sinks/daily_file_sink.h index da4ffc29..7e590164 100644 --- a/include/spdlog/sinks/daily_file_sink.h +++ b/include/spdlog/sinks/daily_file_sink.h @@ -29,8 +29,8 @@ struct daily_filename_calculator { static filename_t calc_filename(const filename_t &filename, const tm &now_tm) { filename_t basename, ext; std::tie(basename, ext) = details::file_helper::split_by_extension(filename); - return fmt_lib::format(SPDLOG_FILENAME_T("{}_{:04d}-{:02d}-{:02d}{}"), basename, now_tm.tm_year + 1900, - now_tm.tm_mon + 1, now_tm.tm_mday, ext); + return fmt_lib::format(SPDLOG_FILENAME_T("{}_{:04d}-{:02d}-{:02d}{}"), basename, now_tm.tm_year + 1900, now_tm.tm_mon + 1, + now_tm.tm_mday, ext); } }; @@ -214,8 +214,8 @@ inline std::shared_ptr daily_logger_format_mt(const std::string &logger_ bool truncate = false, uint16_t max_files = 0, const file_event_handlers &event_handlers = {}) { - return Factory::template create(logger_name, filename, hour, minute, truncate, - max_files, event_handlers); + return Factory::template create(logger_name, filename, hour, minute, truncate, max_files, + event_handlers); } template @@ -238,7 +238,7 @@ inline std::shared_ptr daily_logger_format_st(const std::string &logger_ bool truncate = false, uint16_t max_files = 0, const file_event_handlers &event_handlers = {}) { - return Factory::template create(logger_name, filename, hour, minute, truncate, - max_files, event_handlers); + return Factory::template create(logger_name, filename, hour, minute, truncate, max_files, + event_handlers); } } // namespace spdlog diff --git a/include/spdlog/sinks/dup_filter_sink.h b/include/spdlog/sinks/dup_filter_sink.h index 51db39e5..896f6e0b 100644 --- a/include/spdlog/sinks/dup_filter_sink.h +++ b/include/spdlog/sinks/dup_filter_sink.h @@ -40,8 +40,7 @@ template class dup_filter_sink : public dist_sink { public: template - explicit dup_filter_sink(std::chrono::duration max_skip_duration, - level notification_level = level::info) + explicit dup_filter_sink(std::chrono::duration max_skip_duration, level notification_level = level::info) : max_skip_duration_{max_skip_duration}, log_level_{notification_level} {} @@ -62,8 +61,7 @@ protected: // log the "skipped.." message if (skip_counter_ > 0) { char buf[64]; - auto msg_size = - ::snprintf(buf, sizeof(buf), "Skipped %u duplicate messages..", static_cast(skip_counter_)); + auto msg_size = ::snprintf(buf, sizeof(buf), "Skipped %u duplicate messages..", static_cast(skip_counter_)); if (msg_size > 0 && static_cast(msg_size) < sizeof(buf)) { details::log_msg skipped_msg{msg.source, msg.logger_name, log_level_, string_view_t{buf, static_cast(msg_size)}}; diff --git a/include/spdlog/sinks/hourly_file_sink.h b/include/spdlog/sinks/hourly_file_sink.h index 097303c7..66a7e216 100644 --- a/include/spdlog/sinks/hourly_file_sink.h +++ b/include/spdlog/sinks/hourly_file_sink.h @@ -173,8 +173,7 @@ inline std::shared_ptr hourly_logger_mt(const std::string &logger_name, bool truncate = false, uint16_t max_files = 0, const file_event_handlers &event_handlers = {}) { - return Factory::template create(logger_name, filename, truncate, max_files, - event_handlers); + return Factory::template create(logger_name, filename, truncate, max_files, event_handlers); } template @@ -183,7 +182,6 @@ inline std::shared_ptr hourly_logger_st(const std::string &logger_name, bool truncate = false, uint16_t max_files = 0, const file_event_handlers &event_handlers = {}) { - return Factory::template create(logger_name, filename, truncate, max_files, - event_handlers); + return Factory::template create(logger_name, filename, truncate, max_files, event_handlers); } } // namespace spdlog diff --git a/include/spdlog/sinks/kafka_sink.h b/include/spdlog/sinks/kafka_sink.h index 67c55e5d..06f0d7fd 100644 --- a/include/spdlog/sinks/kafka_sink.h +++ b/include/spdlog/sinks/kafka_sink.h @@ -71,8 +71,8 @@ public: protected: void sink_it_(const details::log_msg &msg) override { - producer_->produce(topic_.get(), 0, RdKafka::Producer::RK_MSG_COPY, (void *)msg.payload.data(), - msg.payload.size(), NULL, NULL); + producer_->produce(topic_.get(), 0, RdKafka::Producer::RK_MSG_COPY, (void *)msg.payload.data(), msg.payload.size(), NULL, + NULL); } void flush_() override { producer_->flush(config_.flush_timeout_ms); } @@ -91,26 +91,22 @@ using kafka_sink_st = kafka_sink; } // namespace sinks template -inline std::shared_ptr kafka_logger_mt(const std::string &logger_name, - spdlog::sinks::kafka_sink_config config) { +inline std::shared_ptr kafka_logger_mt(const std::string &logger_name, spdlog::sinks::kafka_sink_config config) { return Factory::template create(logger_name, config); } template -inline std::shared_ptr kafka_logger_st(const std::string &logger_name, - spdlog::sinks::kafka_sink_config config) { +inline std::shared_ptr kafka_logger_st(const std::string &logger_name, spdlog::sinks::kafka_sink_config config) { return Factory::template create(logger_name, config); } template -inline std::shared_ptr kafka_logger_async_mt(std::string logger_name, - spdlog::sinks::kafka_sink_config config) { +inline std::shared_ptr kafka_logger_async_mt(std::string logger_name, spdlog::sinks::kafka_sink_config config) { return Factory::template create(logger_name, config); } template -inline std::shared_ptr kafka_logger_async_st(std::string logger_name, - spdlog::sinks::kafka_sink_config config) { +inline std::shared_ptr kafka_logger_async_st(std::string logger_name, spdlog::sinks::kafka_sink_config config) { return Factory::template create(logger_name, config); } diff --git a/include/spdlog/sinks/mongo_sink.h b/include/spdlog/sinks/mongo_sink.h index 04a9f2a1..56e21343 100644 --- a/include/spdlog/sinks/mongo_sink.h +++ b/include/spdlog/sinks/mongo_sink.h @@ -58,8 +58,8 @@ protected: if (client_ != nullptr) { auto doc = document{} << "timestamp" << bsoncxx::types::b_date(msg.time) << "level" - << level::to_string_view(msg.log_level).data() << "level_num" << msg.log_level - << "message" << std::string(msg.payload.begin(), msg.payload.end()) << "logger_name" + << level::to_string_view(msg.log_level).data() << "level_num" << msg.log_level << "message" + << std::string(msg.payload.begin(), msg.payload.end()) << "logger_name" << std::string(msg.logger_name.begin(), msg.logger_name.end()) << "thread_id" << static_cast(msg.thread_id) << finalize; client_->database(db_name_).collection(coll_name_).insert_one(doc.view()); diff --git a/include/spdlog/sinks/qt_sinks.h b/include/spdlog/sinks/qt_sinks.h index da5fa824..4147fcac 100644 --- a/include/spdlog/sinks/qt_sinks.h +++ b/include/spdlog/sinks/qt_sinks.h @@ -43,9 +43,8 @@ protected: memory_buf_t formatted; base_sink::formatter_->format(msg, formatted); const string_view_t str = string_view_t(formatted.data(), formatted.size()); - QMetaObject::invokeMethod( - qt_object_, meta_method_.c_str(), Qt::AutoConnection, - Q_ARG(QString, QString::fromUtf8(str.data(), static_cast(str.size())).trimmed())); + QMetaObject::invokeMethod(qt_object_, meta_method_.c_str(), Qt::AutoConnection, + Q_ARG(QString, QString::fromUtf8(str.data(), static_cast(str.size())).trimmed())); } void flush_() override {} @@ -206,8 +205,7 @@ protected: // insert the colorized text cursor.setCharFormat(params.level_color); - cursor.insertText( - params.payload.mid(params.color_range_start, params.color_range_end - params.color_range_start)); + cursor.insertText(params.payload.mid(params.color_range_start, params.color_range_end - params.color_range_start)); // insert the text after the color range with default format cursor.setCharFormat(params.default_color); @@ -266,16 +264,12 @@ inline std::shared_ptr qt_logger_st(const std::string &logger_name, } // log to QObject template -inline std::shared_ptr qt_logger_mt(const std::string &logger_name, - QObject *qt_object, - const std::string &meta_method) { +inline std::shared_ptr qt_logger_mt(const std::string &logger_name, QObject *qt_object, const std::string &meta_method) { return Factory::template create(logger_name, qt_object, meta_method); } template -inline std::shared_ptr qt_logger_st(const std::string &logger_name, - QObject *qt_object, - const std::string &meta_method) { +inline std::shared_ptr qt_logger_st(const std::string &logger_name, QObject *qt_object, const std::string &meta_method) { return Factory::template create(logger_name, qt_object, meta_method); } diff --git a/include/spdlog/sinks/rotating_file_sink.h b/include/spdlog/sinks/rotating_file_sink.h index 2e6470ba..4b0380e3 100644 --- a/include/spdlog/sinks/rotating_file_sink.h +++ b/include/spdlog/sinks/rotating_file_sink.h @@ -68,8 +68,8 @@ inline std::shared_ptr rotating_logger_mt(const std::string &logger_name size_t max_files, bool rotate_on_open = false, const file_event_handlers &event_handlers = {}) { - return Factory::template create(logger_name, filename, max_file_size, max_files, - rotate_on_open, event_handlers); + return Factory::template create(logger_name, filename, max_file_size, max_files, rotate_on_open, + event_handlers); } template @@ -79,7 +79,7 @@ inline std::shared_ptr rotating_logger_st(const std::string &logger_name size_t max_files, bool rotate_on_open = false, const file_event_handlers &event_handlers = {}) { - return Factory::template create(logger_name, filename, max_file_size, max_files, - rotate_on_open, event_handlers); + return Factory::template create(logger_name, filename, max_file_size, max_files, rotate_on_open, + event_handlers); } } // namespace spdlog diff --git a/include/spdlog/sinks/win_eventlog_sink.h b/include/spdlog/sinks/win_eventlog_sink.h index 3e6664ac..ffa28df2 100644 --- a/include/spdlog/sinks/win_eventlog_sink.h +++ b/include/spdlog/sinks/win_eventlog_sink.h @@ -75,8 +75,8 @@ struct win32_error : public spdlog_ex { local_alloc_t format_message_result{}; auto format_message_succeeded = ::FormatMessageA( - FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, - error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&format_message_result.hlocal_, 0, nullptr); + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, error_code, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&format_message_result.hlocal_, 0, nullptr); if (format_message_succeeded && format_message_result.hlocal_) { system_message = fmt_lib::format(" ({})", (LPSTR)format_message_result.hlocal_); @@ -140,8 +140,7 @@ public: // get user token std::vector buffer(static_cast(tusize)); - if (!::GetTokenInformation(current_process_token.token_handle_, TokenUser, (LPVOID)buffer.data(), tusize, - &tusize)) { + if (!::GetTokenInformation(current_process_token.token_handle_, TokenUser, (LPVOID)buffer.data(), tusize, &tusize)) { SPDLOG_THROW(win32_error("GetTokenInformation")); } @@ -210,9 +209,9 @@ protected: formatted.push_back('\0'); LPCSTR lp_str = formatted.data(); - succeeded = static_cast(::ReportEventA(event_log_handle(), eventlog::get_event_type(msg), - eventlog::get_event_category(msg), event_id_, - current_user_sid_.as_sid(), 1, 0, &lp_str, nullptr)); + succeeded = + static_cast(::ReportEventA(event_log_handle(), eventlog::get_event_type(msg), eventlog::get_event_category(msg), + event_id_, current_user_sid_.as_sid(), 1, 0, &lp_str, nullptr)); if (!succeeded) { SPDLOG_THROW(win32_error("ReportEvent")); diff --git a/include/spdlog/source_loc.h b/include/spdlog/source_loc.h index a213b610..db0e9928 100644 --- a/include/spdlog/source_loc.h +++ b/include/spdlog/source_loc.h @@ -40,9 +40,7 @@ struct source_loc { static constexpr source_loc current() { return source_loc{}; } #endif - [[nodiscard]] constexpr bool empty() const noexcept { - return line == 0 || filename == nullptr || short_filename == nullptr; - } + [[nodiscard]] constexpr bool empty() const noexcept { return line == 0 || filename == nullptr || short_filename == nullptr; } const char *filename{nullptr}; const char *short_filename{nullptr}; diff --git a/src/common.cpp b/src/common.cpp index 131e7adf..2d789765 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -10,8 +10,7 @@ namespace spdlog { spdlog::level level_from_str(const std::string &name) noexcept { auto it = std::find(std::begin(level_string_views), std::end(level_string_views), name); - if (it != std::end(level_string_views)) - return static_cast(std::distance(std::begin(level_string_views), it)); + if (it != std::end(level_string_views)) return static_cast(std::distance(std::begin(level_string_views), it)); // check also for "warn" and "err" before giving up.. if (name == "warn") { diff --git a/src/details/os.cpp b/src/details/os.cpp index a15ba50c..6e014d34 100644 --- a/src/details/os.cpp +++ b/src/details/os.cpp @@ -218,8 +218,7 @@ size_t filesize(FILE *f) { int fd = ::fileno(f); #endif // 64 bits(but not in osx, linux/musl or cygwin, where fstat64 is deprecated) - #if ((defined(__linux__) && defined(__GLIBC__)) || defined(__sun) || defined(_AIX)) && \ - (defined(__LP64__) || defined(_LP64)) + #if ((defined(__linux__) && defined(__GLIBC__)) || defined(__sun) || defined(_AIX)) && (defined(__LP64__) || defined(_LP64)) struct stat64 st; if (::fstat64(fd, &st) == 0) { return static_cast(st.st_size); @@ -400,9 +399,9 @@ bool is_color_terminal() noexcept { return true; } - static constexpr std::array terms = {{"ansi", "color", "console", "cygwin", "gnome", - "konsole", "kterm", "linux", "msys", "putty", "rxvt", - "screen", "vt100", "xterm", "alacritty", "vt102"}}; + static constexpr std::array terms = {{"ansi", "color", "console", "cygwin", "gnome", "konsole", "kterm", + "linux", "msys", "putty", "rxvt", "screen", "vt100", "xterm", + "alacritty", "vt102"}}; const char *env_term_p = std::getenv("TERM"); if (env_term_p == nullptr) { @@ -473,8 +472,7 @@ void utf8_to_wstrbuf(string_view_t str, wmemory_buf_t &target) { if (result_size > 0) { target.resize(result_size); - result_size = - ::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, str.data(), str_size, target.data(), result_size); + result_size = ::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, str.data(), str_size, target.data(), result_size); if (result_size > 0) { assert(result_size == target.size()); return; diff --git a/src/details/thread_pool.cpp b/src/details/thread_pool.cpp index bdc5d6ff..0655e523 100644 --- a/src/details/thread_pool.cpp +++ b/src/details/thread_pool.cpp @@ -50,9 +50,7 @@ thread_pool::~thread_pool() { SPDLOG_CATCH_STD } -void thread_pool::post_log(async_logger_ptr &&worker_ptr, - const details::log_msg &msg, - async_overflow_policy overflow_policy) { +void thread_pool::post_log(async_logger_ptr &&worker_ptr, const details::log_msg &msg, async_overflow_policy overflow_policy) { async_msg async_m(std::move(worker_ptr), async_msg_type::log, msg); post_async_msg_(std::move(async_m), overflow_policy); } diff --git a/src/logger.cpp b/src/logger.cpp index 3211d0bc..652ffda9 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -106,8 +106,7 @@ void logger::err_handler_(const std::string &msg) { #if defined(USING_R) && defined(R_R_H) // if in R environment REprintf("[*** LOG ERROR #%04zu ***] [%s] [%s] %s\n", err_counter, date_buf, name().c_str(), msg.c_str()); #else - std::fprintf(stderr, "[*** LOG ERROR #%04zu ***] [%s] [%s] %s\n", err_counter, date_buf, name().c_str(), - msg.c_str()); + std::fprintf(stderr, "[*** LOG ERROR #%04zu ***] [%s] [%s] %s\n", err_counter, date_buf, name().c_str(), msg.c_str()); #endif } } diff --git a/src/pattern_formatter.cpp b/src/pattern_formatter.cpp index 3f38d6e3..e7c05f0d 100644 --- a/src/pattern_formatter.cpp +++ b/src/pattern_formatter.cpp @@ -62,9 +62,7 @@ public: } private: - void pad_it(long count) { - fmt_helper::append_string_view(string_view_t(spaces_.data(), static_cast(count)), dest_); - } + void pad_it(long count) { fmt_helper::append_string_view(string_view_t(spaces_.data(), static_cast(count)), dest_); } const padding_info &padinfo_; memory_buf_t &dest_; @@ -146,8 +144,7 @@ public: }; // Full weekday name -static std::array full_days{ - {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}}; +static std::array full_days{{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}}; template class A_formatter : public flag_formatter { @@ -180,8 +177,8 @@ public: }; // Full month name -static const std::array full_months{{"January", "February", "March", "April", "May", "June", "July", - "August", "September", "October", "November", "December"}}; +static const std::array full_months{ + {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}}; template class B_formatter final : public flag_formatter { @@ -614,9 +611,7 @@ public: explicit color_stop_formatter(padding_info padinfo) : flag_formatter(padinfo) {} - void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - msg.color_range_end = dest.size(); - } + void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { msg.color_range_end = dest.size(); } }; // print source location @@ -635,8 +630,7 @@ public: size_t text_size; if (padinfo_.enabled()) { // calc text size for padding based on "filename:line" - text_size = - std::char_traits::length(msg.source.filename) + ScopedPadder::count_digits(msg.source.line) + 1; + text_size = std::char_traits::length(msg.source.filename) + ScopedPadder::count_digits(msg.source.line) + 1; } else { text_size = 0; } @@ -858,8 +852,7 @@ std::unique_ptr pattern_formatter::clone() const { for (auto &it : custom_handlers_) { cloned_custom_formatters[it.first] = it.second->clone(); } - auto cloned = - std::make_unique(pattern_, pattern_time_type_, eol_, std::move(cloned_custom_formatters)); + auto cloned = std::make_unique(pattern_, pattern_time_type_, eol_, std::move(cloned_custom_formatters)); cloned->need_localtime(need_localtime_); #if defined(__GNUC__) && __GNUC__ < 5 return std::move(cloned); @@ -1088,18 +1081,15 @@ void pattern_formatter::handle_flag_(char flag, details::padding_info padding) { break; case ('u'): // elapsed time since last log message in nanos - formatters_.push_back( - std::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('i'): // elapsed time since last log message in micros - formatters_.push_back( - std::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('o'): // elapsed time since last log message in millis - formatters_.push_back( - std::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('O'): // elapsed time since last log message in seconds @@ -1131,8 +1121,7 @@ void pattern_formatter::handle_flag_(char flag, details::padding_info padding) { // Extract given pad spec (e.g. %8X, %=8X, %-8!X, %8!X, %=8!X, %-8!X, %+8!X) // Advance the given it pass the end of the padding spec found (if any) // Return padding. -details::padding_info pattern_formatter::handle_padspec_(std::string::const_iterator &it, - std::string::const_iterator end) { +details::padding_info pattern_formatter::handle_padspec_(std::string::const_iterator &it, std::string::const_iterator end) { using details::padding_info; using details::scoped_padder; const size_t max_width = 64; diff --git a/src/sinks/basic_file_sink.cpp b/src/sinks/basic_file_sink.cpp index 2455d3ae..b05dae31 100644 --- a/src/sinks/basic_file_sink.cpp +++ b/src/sinks/basic_file_sink.cpp @@ -9,9 +9,7 @@ namespace spdlog { namespace sinks { template -basic_file_sink::basic_file_sink(const filename_t &filename, - bool truncate, - const file_event_handlers &event_handlers) +basic_file_sink::basic_file_sink(const filename_t &filename, bool truncate, const file_event_handlers &event_handlers) : file_helper_{event_handlers} { file_helper_.open(filename, truncate); } diff --git a/src/sinks/rotating_file_sink.cpp b/src/sinks/rotating_file_sink.cpp index 267b66bb..eaa645e7 100644 --- a/src/sinks/rotating_file_sink.cpp +++ b/src/sinks/rotating_file_sink.cpp @@ -113,9 +113,8 @@ void rotating_file_sink::rotate_() { file_helper_.reopen(true); // truncate the log file anyway to prevent it // to grow beyond its limit! current_size_ = 0; - throw_spdlog_ex( - "rotating_file_sink: failed renaming " + filename_to_str(src) + " to " + filename_to_str(target), - errno); + throw_spdlog_ex("rotating_file_sink: failed renaming " + filename_to_str(src) + " to " + filename_to_str(target), + errno); } } } diff --git a/src/sinks/stdout_color_sinks.cpp b/src/sinks/stdout_color_sinks.cpp index 8d5b75eb..c01b326c 100644 --- a/src/sinks/stdout_color_sinks.cpp +++ b/src/sinks/stdout_color_sinks.cpp @@ -44,14 +44,14 @@ template SPDLOG_API std::shared_ptr spdlog::stderr_color_mt spdlog::stderr_color_st( const std::string &logger_name, color_mode mode); -template SPDLOG_API std::shared_ptr spdlog::stdout_color_mt( - const std::string &logger_name, color_mode mode); +template SPDLOG_API std::shared_ptr spdlog::stdout_color_mt(const std::string &logger_name, + color_mode mode); -template SPDLOG_API std::shared_ptr spdlog::stdout_color_st( - const std::string &logger_name, color_mode mode); +template SPDLOG_API std::shared_ptr spdlog::stdout_color_st(const std::string &logger_name, + color_mode mode); -template SPDLOG_API std::shared_ptr spdlog::stderr_color_mt( - const std::string &logger_name, color_mode mode); +template SPDLOG_API std::shared_ptr spdlog::stderr_color_mt(const std::string &logger_name, + color_mode mode); -template SPDLOG_API std::shared_ptr spdlog::stderr_color_st( - const std::string &logger_name, color_mode mode); +template SPDLOG_API std::shared_ptr spdlog::stderr_color_st(const std::string &logger_name, + color_mode mode); diff --git a/src/sinks/wincolor_sink.cpp b/src/sinks/wincolor_sink.cpp index bc844827..f2e9ba03 100644 --- a/src/sinks/wincolor_sink.cpp +++ b/src/sinks/wincolor_sink.cpp @@ -20,14 +20,12 @@ wincolor_sink::wincolor_sink(void *out_handle, color_mode mode) : out_handle_(out_handle) { set_color_mode_impl(mode); // set level colors - colors_.at(level_to_number(level::trace)) = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; // white - colors_.at(level_to_number(level::debug)) = FOREGROUND_GREEN | FOREGROUND_BLUE; // cyan - colors_.at(level_to_number(level::info)) = FOREGROUND_GREEN; // green - colors_.at(level_to_number(level::warn)) = - FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY; // intense yellow - colors_.at(level_to_number(level::err)) = FOREGROUND_RED | FOREGROUND_INTENSITY; // intense red - colors_.at(level_to_number(level::critical)) = BACKGROUND_RED | FOREGROUND_RED | FOREGROUND_GREEN | - FOREGROUND_BLUE | + colors_.at(level_to_number(level::trace)) = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; // white + colors_.at(level_to_number(level::debug)) = FOREGROUND_GREEN | FOREGROUND_BLUE; // cyan + colors_.at(level_to_number(level::info)) = FOREGROUND_GREEN; // green + colors_.at(level_to_number(level::warn)) = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY; // intense yellow + colors_.at(level_to_number(level::err)) = FOREGROUND_RED | FOREGROUND_INTENSITY; // intense red + colors_.at(level_to_number(level::critical)) = BACKGROUND_RED | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY; // intense white on red background colors_.at(level_to_number(level::off)) = 0; } @@ -113,8 +111,7 @@ template void wincolor_sink::print_range_(const memory_buf_t &formatted, size_t start, size_t end) { if (end > start) { auto size = static_cast(end - start); - auto ignored = - ::WriteConsoleA(static_cast(out_handle_), formatted.data() + start, size, nullptr, nullptr); + auto ignored = ::WriteConsoleA(static_cast(out_handle_), formatted.data() + start, size, nullptr, nullptr); (void)(ignored); } } diff --git a/src/spdlog.cpp b/src/spdlog.cpp index 9b5bb02c..825e85e5 100644 --- a/src/spdlog.cpp +++ b/src/spdlog.cpp @@ -12,9 +12,7 @@ namespace spdlog { -void initialize_logger(std::shared_ptr logger) { - details::registry::instance().initialize_logger(std::move(logger)); -} +void initialize_logger(std::shared_ptr logger) { details::registry::instance().initialize_logger(std::move(logger)); } std::shared_ptr get(const std::string &name) { return details::registry::instance().get(name); } @@ -34,17 +32,11 @@ void set_level(level level) { details::registry::instance().set_level(level); } void flush_on(level level) { details::registry::instance().flush_on(level); } -void set_error_handler(void (*handler)(const std::string &msg)) { - details::registry::instance().set_error_handler(handler); -} +void set_error_handler(void (*handler)(const std::string &msg)) { details::registry::instance().set_error_handler(handler); } -void register_logger(std::shared_ptr logger) { - details::registry::instance().register_logger(std::move(logger)); -} +void register_logger(std::shared_ptr logger) { details::registry::instance().register_logger(std::move(logger)); } -void apply_all(const std::function)> &fun) { - details::registry::instance().apply_all(fun); -} +void apply_all(const std::function)> &fun) { details::registry::instance().apply_all(fun); } void drop(const std::string &name) { details::registry::instance().drop(name); } diff --git a/tests/test_async.cpp b/tests/test_async.cpp index a0711bfe..e31ec953 100644 --- a/tests/test_async.cpp +++ b/tests/test_async.cpp @@ -31,8 +31,7 @@ TEST_CASE("discard policy ", "[async]") { size_t messages = 1024; auto tp = std::make_shared(queue_size, 1); - auto logger = - std::make_shared("as", test_sink, tp, spdlog::async_overflow_policy::overrun_oldest); + auto logger = std::make_shared("as", test_sink, tp, spdlog::async_overflow_policy::overrun_oldest); for (size_t i = 0; i < messages; i++) { logger->info("Hello message"); } @@ -47,8 +46,7 @@ TEST_CASE("discard policy discard_new ", "[async]") { size_t messages = 1024; auto tp = std::make_shared(queue_size, 1); - auto logger = - std::make_shared("as", test_sink, tp, spdlog::async_overflow_policy::discard_new); + auto logger = std::make_shared("as", test_sink, tp, spdlog::async_overflow_policy::discard_new); for (size_t i = 0; i < messages; i++) { logger->info("Hello message"); } diff --git a/tests/test_create_dir.cpp b/tests/test_create_dir.cpp index b320da62..7a38d97d 100644 --- a/tests/test_create_dir.cpp +++ b/tests/test_create_dir.cpp @@ -21,18 +21,16 @@ TEST_CASE("create_dir", "[create_dir]") { SPDLOG_FILENAME_T("test_logs/dir1/dir1"))); // test existing REQUIRE(try_create_dir(SPDLOG_FILENAME_T("test_logs/dir1///dir2//"), SPDLOG_FILENAME_T("test_logs/dir1/dir2"))); REQUIRE(try_create_dir(SPDLOG_FILENAME_T("./test_logs/dir1/dir3"), SPDLOG_FILENAME_T("test_logs/dir1/dir3"))); - REQUIRE(try_create_dir(SPDLOG_FILENAME_T("test_logs/../test_logs/dir1/dir4"), - SPDLOG_FILENAME_T("test_logs/dir1/dir4"))); + REQUIRE(try_create_dir(SPDLOG_FILENAME_T("test_logs/../test_logs/dir1/dir4"), SPDLOG_FILENAME_T("test_logs/dir1/dir4"))); #ifdef WIN32 // test backslash folder separator REQUIRE(try_create_dir(SPDLOG_FILENAME_T("test_logs\\dir1\\dir222"), SPDLOG_FILENAME_T("test_logs\\dir1\\dir222"))); - REQUIRE( - try_create_dir(SPDLOG_FILENAME_T("test_logs\\dir1\\dir223\\"), SPDLOG_FILENAME_T("test_logs\\dir1\\dir223\\"))); + REQUIRE(try_create_dir(SPDLOG_FILENAME_T("test_logs\\dir1\\dir223\\"), SPDLOG_FILENAME_T("test_logs\\dir1\\dir223\\"))); REQUIRE(try_create_dir(SPDLOG_FILENAME_T(".\\test_logs\\dir1\\dir2\\dir99\\..\\dir23"), SPDLOG_FILENAME_T("test_logs\\dir1\\dir2\\dir23"))); - REQUIRE(try_create_dir(SPDLOG_FILENAME_T("test_logs\\..\\test_logs\\dir1\\dir5"), - SPDLOG_FILENAME_T("test_logs\\dir1\\dir5"))); + REQUIRE( + try_create_dir(SPDLOG_FILENAME_T("test_logs\\..\\test_logs\\dir1\\dir5"), SPDLOG_FILENAME_T("test_logs\\dir1\\dir5"))); #endif } diff --git a/tests/test_daily_and_rotation_loggers.cpp b/tests/test_daily_and_rotation_loggers.cpp index d26fcaf7..7d96a79d 100644 --- a/tests/test_daily_and_rotation_loggers.cpp +++ b/tests/test_daily_and_rotation_loggers.cpp @@ -31,8 +31,8 @@ TEST_CASE("daily_logger with dateonly calculator", "[daily_logger]") { spdlog::filename_t basename = SPDLOG_FILENAME_T("test_logs/daily_dateonly"); std::tm tm = spdlog::details::os::localtime(); filename_memory_buf_t w; - spdlog::fmt_lib::format_to(std::back_inserter(w), SPDLOG_FILENAME_T("{}_{:04d}-{:02d}-{:02d}"), basename, - tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday); + spdlog::fmt_lib::format_to(std::back_inserter(w), SPDLOG_FILENAME_T("{}_{:04d}-{:02d}-{:02d}"), basename, tm.tm_year + 1900, + tm.tm_mon + 1, tm.tm_mday); auto logger = spdlog::create("logger", basename, 0, 0); for (int i = 0; i < 10; ++i) { @@ -62,8 +62,8 @@ TEST_CASE("daily_logger with custom calculator", "[daily_logger]") { spdlog::filename_t basename = SPDLOG_FILENAME_T("test_logs/daily_dateonly"); std::tm tm = spdlog::details::os::localtime(); filename_memory_buf_t w; - spdlog::fmt_lib::format_to(std::back_inserter(w), SPDLOG_FILENAME_T("{}{:04d}{:02d}{:02d}"), basename, - tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday); + spdlog::fmt_lib::format_to(std::back_inserter(w), SPDLOG_FILENAME_T("{}{:04d}{:02d}{:02d}"), basename, tm.tm_year + 1900, + tm.tm_mon + 1, tm.tm_mday); auto logger = spdlog::create("logger", basename, 0, 0); for (int i = 0; i < 10; ++i) { @@ -100,8 +100,8 @@ TEST_CASE("rotating_file_sink::calc_filename3", "[rotating_file_sink]") { TEST_CASE("daily_file_sink::daily_filename_calculator", "[daily_file_sink]") { // daily_YYYY-MM-DD_hh-mm.txt - auto filename = spdlog::sinks::daily_filename_calculator::calc_filename(SPDLOG_FILENAME_T("daily.txt"), - spdlog::details::os::localtime()); + auto filename = + spdlog::sinks::daily_filename_calculator::calc_filename(SPDLOG_FILENAME_T("daily.txt"), spdlog::details::os::localtime()); // date regex based on https://www.regular-expressions.info/dates.html std::basic_regex re( SPDLOG_FILENAME_T(R"(^daily_(19|20)\d\d-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])\.txt$)")); @@ -113,11 +113,10 @@ TEST_CASE("daily_file_sink::daily_filename_calculator", "[daily_file_sink]") { TEST_CASE("daily_file_sink::daily_filename_format_calculator", "[daily_file_sink]") { std::tm tm = spdlog::details::os::localtime(); // example-YYYY-MM-DD.log - auto filename = - spdlog::sinks::daily_filename_format_calculator::calc_filename(SPDLOG_FILENAME_T("example-%Y-%m-%d.log"), tm); + auto filename = spdlog::sinks::daily_filename_format_calculator::calc_filename(SPDLOG_FILENAME_T("example-%Y-%m-%d.log"), tm); - REQUIRE(filename == spdlog::fmt_lib::format(SPDLOG_FILENAME_T("example-{:04d}-{:02d}-{:02d}.log"), - tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday)); + REQUIRE(filename == spdlog::fmt_lib::format(SPDLOG_FILENAME_T("example-{:04d}-{:02d}-{:02d}.log"), tm.tm_year + 1900, + tm.tm_mon + 1, tm.tm_mday)); } /* Test removal of old files */ diff --git a/tests/test_errors.cpp b/tests/test_errors.cpp index d36aa40b..06a0368e 100644 --- a/tests/test_errors.cpp +++ b/tests/test_errors.cpp @@ -12,9 +12,7 @@ class failing_sink : public spdlog::sinks::base_sink { protected: - void sink_it_(const spdlog::details::log_msg &) final { - throw std::runtime_error("some error happened during log"); - } + void sink_it_(const spdlog::details::log_msg &) final { throw std::runtime_error("some error happened during log"); } void flush_() final { throw std::runtime_error("some error happened during flush"); } }; diff --git a/tests/test_eventlog.cpp b/tests/test_eventlog.cpp index 398f67d9..23644eaa 100644 --- a/tests/test_eventlog.cpp +++ b/tests/test_eventlog.cpp @@ -55,10 +55,8 @@ TEST_CASE("eventlog", "[eventlog]") { test_sink->set_pattern("%v"); - test_single_print([&test_logger](std::string const &msg) { test_logger.trace(msg); }, "my trace message", - EVENTLOG_SUCCESS); - test_single_print([&test_logger](std::string const &msg) { test_logger.debug(msg); }, "my debug message", - EVENTLOG_SUCCESS); + test_single_print([&test_logger](std::string const &msg) { test_logger.trace(msg); }, "my trace message", EVENTLOG_SUCCESS); + test_single_print([&test_logger](std::string const &msg) { test_logger.debug(msg); }, "my debug message", EVENTLOG_SUCCESS); test_single_print([&test_logger](std::string const &msg) { test_logger.info(msg); }, "my info message", EVENTLOG_INFORMATION_TYPE); test_single_print([&test_logger](std::string const &msg) { test_logger.warn(msg); }, "my warn message", diff --git a/tests/test_file_helper.cpp b/tests/test_file_helper.cpp index 3a5ccc49..0d7c4630 100644 --- a/tests/test_file_helper.cpp +++ b/tests/test_file_helper.cpp @@ -80,22 +80,17 @@ TEST_CASE("file_helper_split_by_extension", "[file_helper::split_by_extension()] test_split_ext(SPDLOG_FILENAME_T(".mylog.txt"), SPDLOG_FILENAME_T(".mylog"), SPDLOG_FILENAME_T(".txt")); test_split_ext(SPDLOG_FILENAME_T(".mylog"), SPDLOG_FILENAME_T(".mylog"), SPDLOG_FILENAME_T("")); test_split_ext(SPDLOG_FILENAME_T("/aaa/bb.d/mylog"), SPDLOG_FILENAME_T("/aaa/bb.d/mylog"), SPDLOG_FILENAME_T("")); - test_split_ext(SPDLOG_FILENAME_T("/aaa/bb.d/mylog.txt"), SPDLOG_FILENAME_T("/aaa/bb.d/mylog"), - SPDLOG_FILENAME_T(".txt")); - test_split_ext(SPDLOG_FILENAME_T("aaa/bbb/ccc/mylog.txt"), SPDLOG_FILENAME_T("aaa/bbb/ccc/mylog"), - SPDLOG_FILENAME_T(".txt")); - test_split_ext(SPDLOG_FILENAME_T("aaa/bbb/ccc/mylog."), SPDLOG_FILENAME_T("aaa/bbb/ccc/mylog."), - SPDLOG_FILENAME_T("")); + test_split_ext(SPDLOG_FILENAME_T("/aaa/bb.d/mylog.txt"), SPDLOG_FILENAME_T("/aaa/bb.d/mylog"), SPDLOG_FILENAME_T(".txt")); + test_split_ext(SPDLOG_FILENAME_T("aaa/bbb/ccc/mylog.txt"), SPDLOG_FILENAME_T("aaa/bbb/ccc/mylog"), SPDLOG_FILENAME_T(".txt")); + test_split_ext(SPDLOG_FILENAME_T("aaa/bbb/ccc/mylog."), SPDLOG_FILENAME_T("aaa/bbb/ccc/mylog."), SPDLOG_FILENAME_T("")); test_split_ext(SPDLOG_FILENAME_T("aaa/bbb/ccc/.mylog.txt"), SPDLOG_FILENAME_T("aaa/bbb/ccc/.mylog"), SPDLOG_FILENAME_T(".txt")); test_split_ext(SPDLOG_FILENAME_T("/aaa/bbb/ccc/mylog.txt"), SPDLOG_FILENAME_T("/aaa/bbb/ccc/mylog"), SPDLOG_FILENAME_T(".txt")); - test_split_ext(SPDLOG_FILENAME_T("/aaa/bbb/ccc/.mylog"), SPDLOG_FILENAME_T("/aaa/bbb/ccc/.mylog"), - SPDLOG_FILENAME_T("")); + test_split_ext(SPDLOG_FILENAME_T("/aaa/bbb/ccc/.mylog"), SPDLOG_FILENAME_T("/aaa/bbb/ccc/.mylog"), SPDLOG_FILENAME_T("")); test_split_ext(SPDLOG_FILENAME_T("../mylog.txt"), SPDLOG_FILENAME_T("../mylog"), SPDLOG_FILENAME_T(".txt")); test_split_ext(SPDLOG_FILENAME_T(".././mylog.txt"), SPDLOG_FILENAME_T(".././mylog"), SPDLOG_FILENAME_T(".txt")); - test_split_ext(SPDLOG_FILENAME_T(".././mylog.txt/xxx"), SPDLOG_FILENAME_T(".././mylog.txt/xxx"), - SPDLOG_FILENAME_T("")); + test_split_ext(SPDLOG_FILENAME_T(".././mylog.txt/xxx"), SPDLOG_FILENAME_T(".././mylog.txt/xxx"), SPDLOG_FILENAME_T("")); test_split_ext(SPDLOG_FILENAME_T("/mylog.txt"), SPDLOG_FILENAME_T("/mylog"), SPDLOG_FILENAME_T(".txt")); test_split_ext(SPDLOG_FILENAME_T("//mylog.txt"), SPDLOG_FILENAME_T("//mylog"), SPDLOG_FILENAME_T(".txt")); test_split_ext(SPDLOG_FILENAME_T(""), SPDLOG_FILENAME_T(""), SPDLOG_FILENAME_T("")); diff --git a/tests/test_file_logging.cpp b/tests/test_file_logging.cpp index ad53bc3d..5ba4b15b 100644 --- a/tests/test_file_logging.cpp +++ b/tests/test_file_logging.cpp @@ -22,8 +22,7 @@ TEST_CASE("simple_file_logger", "[simple_logger]") { logger->flush(); require_message_count(SIMPLE_LOG, 2); using spdlog::details::os::default_eol; - REQUIRE(file_contents(SIMPLE_LOG) == - spdlog::fmt_lib::format("Test message 1{}Test message 2{}", default_eol, default_eol)); + REQUIRE(file_contents(SIMPLE_LOG) == spdlog::fmt_lib::format("Test message 1{}Test message 2{}", default_eol, default_eol)); } TEST_CASE("flush_on", "[flush_on]") { @@ -42,9 +41,8 @@ TEST_CASE("flush_on", "[flush_on]") { require_message_count(SIMPLE_LOG, 3); using spdlog::details::os::default_eol; - REQUIRE(file_contents(SIMPLE_LOG) == - spdlog::fmt_lib::format("Should not be flushed{}Test message 1{}Test message 2{}", default_eol, default_eol, - default_eol)); + REQUIRE(file_contents(SIMPLE_LOG) == spdlog::fmt_lib::format("Should not be flushed{}Test message 1{}Test message 2{}", + default_eol, default_eol, default_eol)); } TEST_CASE("rotating_file_logger1", "[rotating_logger]") { diff --git a/tests/test_log_level.cpp b/tests/test_log_level.cpp index ee86deda..2bb310de 100644 --- a/tests/test_log_level.cpp +++ b/tests/test_log_level.cpp @@ -37,8 +37,7 @@ TEST_CASE("test_sink_levels", "[log_level]") { auto get_expected_messages(spdlog::level level) { // expected messages for each level static const std::map> messages = { - {spdlog::level::trace, - {"trace hello", "debug hello", "info hello", "warning hello", "error hello", "critical hello"}}, + {spdlog::level::trace, {"trace hello", "debug hello", "info hello", "warning hello", "error hello", "critical hello"}}, {spdlog::level::debug, {"debug hello", "info hello", "warning hello", "error hello", "critical hello"}}, {spdlog::level::info, {"info hello", "warning hello", "error hello", "critical hello"}}, {spdlog::level::warn, {"warning hello", "error hello", "critical hello"}}, diff --git a/tests/test_pattern_formatter.cpp b/tests/test_pattern_formatter.cpp index 69c37af1..1da38ed3 100644 --- a/tests/test_pattern_formatter.cpp +++ b/tests/test_pattern_formatter.cpp @@ -42,15 +42,14 @@ TEST_CASE("short level", "[pattern_formatter]") { } TEST_CASE("name", "[pattern_formatter]") { - REQUIRE(log_to_str("Some message", "[%n] %v", spdlog::pattern_time_type::local, "\n") == - "[pattern_tester] Some message\n"); + REQUIRE(log_to_str("Some message", "[%n] %v", spdlog::pattern_time_type::local, "\n") == "[pattern_tester] Some message\n"); } TEST_CASE("date MM/DD/YY ", "[pattern_formatter]") { auto now_tm = spdlog::details::os::localtime(); std::stringstream oss; - oss << std::setfill('0') << std::setw(2) << now_tm.tm_mon + 1 << "/" << std::setw(2) << now_tm.tm_mday << "/" - << std::setw(2) << (now_tm.tm_year + 1900) % 1000 << " Some message\n"; + oss << std::setfill('0') << std::setw(2) << now_tm.tm_mon + 1 << "/" << std::setw(2) << now_tm.tm_mday << "/" << std::setw(2) + << (now_tm.tm_year + 1900) % 1000 << " Some message\n"; REQUIRE(log_to_str("Some message", "%D %v", spdlog::pattern_time_type::local, "\n") == oss.str()); } @@ -126,24 +125,18 @@ TEST_CASE("color range test6", "[pattern_formatter]") { // TEST_CASE("level_left_padded", "[pattern_formatter]") { - REQUIRE(log_to_str("Some message", "[%8l] %v", spdlog::pattern_time_type::local, "\n") == - "[ info] Some message\n"); - REQUIRE(log_to_str("Some message", "[%8!l] %v", spdlog::pattern_time_type::local, "\n") == - "[ info] Some message\n"); + REQUIRE(log_to_str("Some message", "[%8l] %v", spdlog::pattern_time_type::local, "\n") == "[ info] Some message\n"); + REQUIRE(log_to_str("Some message", "[%8!l] %v", spdlog::pattern_time_type::local, "\n") == "[ info] Some message\n"); } TEST_CASE("level_right_padded", "[pattern_formatter]") { - REQUIRE(log_to_str("Some message", "[%-8l] %v", spdlog::pattern_time_type::local, "\n") == - "[info ] Some message\n"); - REQUIRE(log_to_str("Some message", "[%-8!l] %v", spdlog::pattern_time_type::local, "\n") == - "[info ] Some message\n"); + REQUIRE(log_to_str("Some message", "[%-8l] %v", spdlog::pattern_time_type::local, "\n") == "[info ] Some message\n"); + REQUIRE(log_to_str("Some message", "[%-8!l] %v", spdlog::pattern_time_type::local, "\n") == "[info ] Some message\n"); } TEST_CASE("level_center_padded", "[pattern_formatter]") { - REQUIRE(log_to_str("Some message", "[%=8l] %v", spdlog::pattern_time_type::local, "\n") == - "[ info ] Some message\n"); - REQUIRE(log_to_str("Some message", "[%=8!l] %v", spdlog::pattern_time_type::local, "\n") == - "[ info ] Some message\n"); + REQUIRE(log_to_str("Some message", "[%=8l] %v", spdlog::pattern_time_type::local, "\n") == "[ info ] Some message\n"); + REQUIRE(log_to_str("Some message", "[%=8!l] %v", spdlog::pattern_time_type::local, "\n") == "[ info ] Some message\n"); } TEST_CASE("short level_left_padded", "[pattern_formatter]") { @@ -162,20 +155,17 @@ TEST_CASE("short level_center_padded", "[pattern_formatter]") { } TEST_CASE("left_padded_short", "[pattern_formatter]") { - REQUIRE(log_to_str("Some message", "[%3n] %v", spdlog::pattern_time_type::local, "\n") == - "[pattern_tester] Some message\n"); + REQUIRE(log_to_str("Some message", "[%3n] %v", spdlog::pattern_time_type::local, "\n") == "[pattern_tester] Some message\n"); REQUIRE(log_to_str("Some message", "[%3!n] %v", spdlog::pattern_time_type::local, "\n") == "[pat] Some message\n"); } TEST_CASE("right_padded_short", "[pattern_formatter]") { - REQUIRE(log_to_str("Some message", "[%-3n] %v", spdlog::pattern_time_type::local, "\n") == - "[pattern_tester] Some message\n"); + REQUIRE(log_to_str("Some message", "[%-3n] %v", spdlog::pattern_time_type::local, "\n") == "[pattern_tester] Some message\n"); REQUIRE(log_to_str("Some message", "[%-3!n] %v", spdlog::pattern_time_type::local, "\n") == "[pat] Some message\n"); } TEST_CASE("center_padded_short", "[pattern_formatter]") { - REQUIRE(log_to_str("Some message", "[%=3n] %v", spdlog::pattern_time_type::local, "\n") == - "[pattern_tester] Some message\n"); + REQUIRE(log_to_str("Some message", "[%=3n] %v", spdlog::pattern_time_type::local, "\n") == "[pattern_tester] Some message\n"); REQUIRE(log_to_str("Some message", "[%=3!n] %v", spdlog::pattern_time_type::local, "\n") == "[pat] Some message\n"); } @@ -220,13 +210,11 @@ TEST_CASE("padding_truncate_funcname", "[pattern_formatter]") { auto formatter = std::unique_ptr(new spdlog::pattern_formatter(pattern)); test_sink.set_formatter(std::move(formatter)); - spdlog::details::log_msg msg1{spdlog::source_loc{"ignored", 1, "func"}, "test_logger", spdlog::level::info, - "message"}; + spdlog::details::log_msg msg1{spdlog::source_loc{"ignored", 1, "func"}, "test_logger", spdlog::level::info, "message"}; test_sink.log(msg1); REQUIRE(test_sink.lines()[0] == "message [ func]"); - spdlog::details::log_msg msg2{spdlog::source_loc{"ignored", 1, "function"}, "test_logger", spdlog::level::info, - "message"}; + spdlog::details::log_msg msg2{spdlog::source_loc{"ignored", 1, "function"}, "test_logger", spdlog::level::info, "message"}; test_sink.log(msg2); REQUIRE(test_sink.lines()[1] == "message [funct]"); } @@ -238,8 +226,7 @@ TEST_CASE("padding_funcname", "[pattern_formatter]") { auto formatter = std::unique_ptr(new spdlog::pattern_formatter(pattern)); test_sink.set_formatter(std::move(formatter)); - spdlog::details::log_msg msg1{spdlog::source_loc{"ignored", 1, "func"}, "test_logger", spdlog::level::info, - "message"}; + spdlog::details::log_msg msg1{spdlog::source_loc{"ignored", 1, "func"}, "test_logger", spdlog::level::info, "message"}; test_sink.log(msg1); REQUIRE(test_sink.lines()[0] == "message [ func]"); @@ -293,8 +280,7 @@ TEST_CASE("clone-formatter", "[pattern_formatter]") { TEST_CASE("clone-formatter-2", "[pattern_formatter]") { using spdlog::pattern_time_type; - auto formatter_1 = - std::make_shared("%D %X [%] [%n] %v", pattern_time_type::utc, "xxxxxx\n"); + auto formatter_1 = std::make_shared("%D %X [%] [%n] %v", pattern_time_type::utc, "xxxxxx\n"); auto formatter_2 = formatter_1->clone(); std::string logger_name = "test2"; spdlog::details::log_msg msg(logger_name, spdlog::level::info, "some message"); @@ -328,9 +314,7 @@ public: std::string some_txt; - std::unique_ptr clone() const override { - return std::make_unique(some_txt); - } + std::unique_ptr clone() const override { return std::make_unique(some_txt); } }; // test clone with custom flag formatters TEST_CASE("clone-custom_formatter", "[pattern_formatter]") { @@ -345,8 +329,7 @@ TEST_CASE("clone-custom_formatter", "[pattern_formatter]") { formatter_1->format(msg, formatted_1); formatter_2->format(msg, formatted_2); - auto expected = - spdlog::fmt_lib::format("[logger-name] [custom_output] some message{}", spdlog::details::os::default_eol); + auto expected = spdlog::fmt_lib::format("[logger-name] [custom_output] some message{}", spdlog::details::os::default_eol); REQUIRE(to_string_view(formatted_1) == expected); REQUIRE(to_string_view(formatted_2) == expected); @@ -416,8 +399,7 @@ TEST_CASE("custom flags", "[pattern_formatter]") { spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::level::info, "some message"); formatter->format(msg, formatted); - auto expected = - spdlog::fmt_lib::format("[logger-name] [custom1] [custom2] some message{}", spdlog::details::os::default_eol); + auto expected = spdlog::fmt_lib::format("[logger-name] [custom1] [custom2] some message{}", spdlog::details::os::default_eol); REQUIRE(to_string_view(formatted) == expected); } @@ -432,8 +414,8 @@ TEST_CASE("custom flags-padding", "[pattern_formatter]") { spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::level::info, "some message"); formatter->format(msg, formatted); - auto expected = spdlog::fmt_lib::format("[logger-name] [custom1] [ custom2] some message{}", - spdlog::details::os::default_eol); + auto expected = + spdlog::fmt_lib::format("[logger-name] [custom1] [ custom2] some message{}", spdlog::details::os::default_eol); REQUIRE(to_string_view(formatted) == expected); } diff --git a/tests/test_registry.cpp b/tests/test_registry.cpp index 75c019a6..9ae17be7 100644 --- a/tests/test_registry.cpp +++ b/tests/test_registry.cpp @@ -28,8 +28,7 @@ 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()); + auto logger2 = std::make_shared(tested_logger_name2, std::make_shared()); spdlog::register_logger(logger2); int counter = 0; @@ -96,8 +95,7 @@ TEST_CASE("disable automatic registration", "[registry]") { spdlog::set_level(level); // but disable automatic registration spdlog::set_automatic_registration(false); - auto logger1 = - spdlog::create(tested_logger_name, SPDLOG_FILENAME_T("filename"), 11, 59); + auto logger1 = spdlog::create(tested_logger_name, SPDLOG_FILENAME_T("filename"), 11, 59); auto logger2 = spdlog::create_async(tested_logger_name2); // loggers should not be part of the registry REQUIRE_FALSE(spdlog::get(tested_logger_name));