diff --git a/CMakeLists.txt b/CMakeLists.txt index a56bd103..8cb45bfb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,7 @@ endif() if(NOT DEFINED CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 17) elseif(CMAKE_CXX_STANDARD LESS 17) - message(FATAL_ERROR "Minimum supported CMAKE_CXX_STANDARD is 17, but CMAKE_CXX_STANDARD is set to a lower value.") + message(FATAL_ERROR "Minimum supported CMAKE_CXX_STANDARD is 17, but CMAKE_CXX_STANDARD is set to a lower value.") endif() set(CMAKE_CXX_STANDARD_REQUIRED ON) diff --git a/example/example.cpp b/example/example.cpp index 05a5a4af..2b88bf56 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -27,9 +27,9 @@ void custom_flags_example(); void file_events_example(); void replace_default_logger_example(); -#define SPDLOG_EMIT_SOURCE_LOCATION // define if you want to log the source file/line/function name. +//#define SPDLOG_EMIT_SOURCE_LOCATION // define if you want to log the source file/line/function name. #include "spdlog/spdlog.h" -#include "spdlog/cfg/env.h" // support for loading levels from the environment variable +#include "spdlog/cfg/env.h" // support for loading levels from the environment variable int main(int, char *[]) { @@ -37,7 +37,6 @@ int main(int, char *[]) load_levels_example(); spdlog::info("Welcome to spdlog version {}.{}.{} !", SPDLOG_VER_MAJOR, SPDLOG_VER_MINOR, SPDLOG_VER_PATCH); - spdlog::warn("Easy padding in numbers like {:08d}", 12); spdlog::critical("Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}", 42); spdlog::info("Support for floats {:03.2f}", 1.23456); diff --git a/include/spdlog/common.h b/include/spdlog/common.h index 1de2ee86..bcb30387 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -18,14 +18,13 @@ #include #include -# if __cpp_lib_source_location >= 201907 -# include -# define SPDLOG_STD_SOURCE_LOCATION -# elif __has_include() -# include -# define SPDLOG_EXPERIMENTAL_SOURCE_LOCATION -# endif - +#if __cpp_lib_source_location >= 201907 +# include +# define SPDLOG_STD_SOURCE_LOCATION +#elif __has_include() +# include +# define SPDLOG_EXPERIMENTAL_SOURCE_LOCATION +#endif #ifdef SPDLOG_USE_STD_FORMAT # if __cpp_lib_format >= 202207L @@ -67,7 +66,6 @@ # define SPDLOG_FMT_STRING(format_string) format_string #endif - #ifndef SPDLOG_FUNCTION # define SPDLOG_FUNCTION static_cast(__FUNCTION__) #endif @@ -124,7 +122,6 @@ using format_string_t = std::format_string; using format_string_t = std::string_view; # endif - # define SPDLOG_BUF_TO_STRING(x) x #else // use fmt lib instead of std::format namespace fmt_lib = fmt; @@ -164,7 +161,7 @@ using level_t = std::atomic; #endif // Is convertable to string_view_t ? -template +template using is_convertible_to_sv = std::enable_if_t>; // Log level enum @@ -248,7 +245,6 @@ private: [[noreturn]] SPDLOG_API void throw_spdlog_ex(const std::string &msg, int last_errno); [[noreturn]] SPDLOG_API void throw_spdlog_ex(std::string msg); - struct source_loc { constexpr source_loc() = default; @@ -264,14 +260,15 @@ struct source_loc return source_loc{source_location.file_name(), source_location.line(), source_location.function_name()}; } #elif defined(SPDLOG_EXPERIMENTAL_SOURCE_LOCATION) - static constexpr source_loc current(const std::experimental::source_location source_location = std::experimental::source_location::current()) + static constexpr source_loc current( + const std::experimental::source_location source_location = std::experimental::source_location::current()) { return source_loc{source_location.file_name(), source_location.line(), source_location.function_name()}; } #else // no source location support static constexpr source_loc current() { - return source_loc{}; + return source_loc{}; } #endif @@ -290,8 +287,10 @@ struct loc_with_fmt source_loc loc; string_view_t fmt_string; template> - constexpr loc_with_fmt(S fmt_str, source_loc loc = source_loc::current()) noexcept: - loc(loc), fmt_string(fmt_str) {} + constexpr loc_with_fmt(S fmt_str, source_loc loc = source_loc::current()) noexcept + : loc(loc) + , fmt_string(fmt_str) + {} }; struct file_event_handlers @@ -349,7 +348,6 @@ constexpr std::basic_string_view to_string_view(std::basic_format_string(args)...); } - template, - typename... Args> + template, typename... Args> void log(source_loc loc, level::level_enum lvl, S fmt, Args &&...args) { if (should_log(lvl)) @@ -105,8 +103,7 @@ public: } // log with no format string, just string message - template> + template> void log(source_loc loc, level::level_enum lvl, S msg) { if (should_log(lvl)) @@ -282,7 +279,6 @@ public: } #endif - // return true logging is enabled for the given level. [[nodiscard]] bool should_log(level::level_enum msg_level) const { @@ -352,7 +348,7 @@ protected: // log the given message (if the given log level is high enough) virtual void sink_it_(const details::log_msg &msg) { - assert (should_log(msg.level)); + assert(should_log(msg.level)); for (auto &sink : sinks_) { if (sink->should_log(msg.level)) diff --git a/include/spdlog/sinks/ringbuffer_sink.h b/include/spdlog/sinks/ringbuffer_sink.h index beaa793a..cbb58215 100644 --- a/include/spdlog/sinks/ringbuffer_sink.h +++ b/include/spdlog/sinks/ringbuffer_sink.h @@ -31,7 +31,7 @@ public: : q_{n_items} {} - void drain_raw(std::function callback) + void drain_raw(std::function callback) { std::lock_guard lock(base_sink::mutex_); while (!q_.empty()) @@ -49,7 +49,7 @@ public: { formatted.clear(); base_sink::formatter_->format(q_.front(), formatted); - callback(std::string_view (formatted.data(), formatted.size())); + callback(std::string_view(formatted.data(), formatted.size())); q_.pop_front(); } } diff --git a/include/spdlog/sinks/win_eventlog_sink.h b/include/spdlog/sinks/win_eventlog_sink.h index 819ad301..fb12e290 100644 --- a/include/spdlog/sinks/win_eventlog_sink.h +++ b/include/spdlog/sinks/win_eventlog_sink.h @@ -51,7 +51,9 @@ struct local_alloc_t { HLOCAL hlocal_; - constexpr local_alloc_t() noexcept : hlocal_(nullptr) {} + constexpr local_alloc_t() noexcept + : hlocal_(nullptr) + {} local_alloc_t(local_alloc_t const &) = delete; local_alloc_t &operator=(local_alloc_t const &) = delete; diff --git a/include/spdlog/spdlog.h b/include/spdlog/spdlog.h index dee8193c..1eaf737c 100644 --- a/include/spdlog/spdlog.h +++ b/include/spdlog/spdlog.h @@ -122,8 +122,6 @@ SPDLOG_API spdlog::logger *default_logger_raw(); SPDLOG_API void set_default_logger(std::shared_ptr default_logger); - - // Initialize logger level based on environment configs. // // Useful for applying SPDLOG_LEVEL to manually created loggers. diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7d93665b..fc6f2a79 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -45,8 +45,7 @@ set(SPDLOG_UTESTS_SOURCES test_time_point.cpp test_stopwatch.cpp test_circular_q.cpp - test_ringbuffer_sink.cpp -) + test_ringbuffer_sink.cpp) if(NOT SPDLOG_NO_EXCEPTIONS) list(APPEND SPDLOG_UTESTS_SOURCES test_errors.cpp) diff --git a/tests/test_circular_q.cpp b/tests/test_circular_q.cpp index b9ace4dc..67fad266 100644 --- a/tests/test_circular_q.cpp +++ b/tests/test_circular_q.cpp @@ -80,7 +80,6 @@ TEST_CASE("test_full", "[circular_q]") REQUIRE(q2.full()); } - TEST_CASE("test_operator[]", "[circular_q]") { q_type q(2); @@ -90,13 +89,12 @@ TEST_CASE("test_operator[]", "[circular_q]") REQUIRE(q[1] == 200); } - TEST_CASE("test_operator=", "[circular_q]") { q_type q1(2); q1.push_back(100); q1.push_back(200); - q_type q2 = q1; + q_type q2 = q1; REQUIRE(q2.size() == 2); REQUIRE(q2[0] == 100); REQUIRE(q2[1] == 200); @@ -114,7 +112,7 @@ TEST_CASE("test_overrun_counter", "[circular_q]") { q_type q(2); REQUIRE(q.overrun_counter() == 0); - for(size_t i=0; i<10; i++) + for (size_t i = 0; i < 10; i++) { q.push_back(100); } @@ -140,7 +138,3 @@ TEST_CASE("test_move", "[circular_q]") REQUIRE(q1.empty()); REQUIRE(q1.overrun_counter() == 0); } - - - - diff --git a/tests/test_misc.cpp b/tests/test_misc.cpp index b3118e92..57defb01 100644 --- a/tests/test_misc.cpp +++ b/tests/test_misc.cpp @@ -25,7 +25,6 @@ TEST_CASE("basic_logging ", "[basic_logging]") // std::string REQUIRE(log_info(std::string("Hello")) == "Hello"); REQUIRE(log_info(std::string()).empty()); - } TEST_CASE("log_levels", "[log_levels]")