From dc030ec53ce9e4005156049ffb065edcca2fb2f7 Mon Sep 17 00:00:00 2001 From: gabime Date: Tue, 16 Nov 2021 23:44:35 +0200 Subject: [PATCH] clang-format --- bench/bench.cpp | 8 +- example/example.cpp | 2 +- include/spdlog/async.h | 6 +- include/spdlog/common.h | 2 +- include/spdlog/details/file_helper-inl.h | 2 +- include/spdlog/details/file_helper.h | 2 +- include/spdlog/details/fmt_helper.h | 10 +-- include/spdlog/details/os-inl.h | 6 +- include/spdlog/details/synchronous_factory.h | 2 +- include/spdlog/details/tcp_client-windows.h | 8 +- include/spdlog/details/udp_client-windows.h | 5 +- include/spdlog/details/udp_client.h | 8 +- include/spdlog/fmt/bin_to_hex.h | 2 +- include/spdlog/logger.h | 46 +++++----- include/spdlog/pattern_formatter.h | 2 +- include/spdlog/sinks/basic_file_sink-inl.h | 2 +- include/spdlog/sinks/basic_file_sink.h | 8 +- include/spdlog/sinks/daily_file_sink.h | 27 +++--- include/spdlog/sinks/hourly_file_sink.h | 11 +-- include/spdlog/sinks/msvc_sink.h | 6 +- include/spdlog/sinks/qt_sinks.h | 89 ++++++++++--------- include/spdlog/sinks/rotating_file_sink-inl.h | 2 +- include/spdlog/sinks/rotating_file_sink.h | 17 ++-- include/spdlog/sinks/udp_sink.h | 2 +- include/spdlog/sinks/win_eventlog_sink.h | 4 +- include/spdlog/spdlog.h | 34 +++---- include/spdlog/stopwatch.h | 2 +- tests/test_daily_logger.cpp | 34 +++---- tests/test_pattern_formatter.cpp | 2 +- 29 files changed, 184 insertions(+), 167 deletions(-) diff --git a/bench/bench.cpp b/bench/bench.cpp index af08c7ac..8a46837a 100644 --- a/bench/bench.cpp +++ b/bench/bench.cpp @@ -160,8 +160,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, int(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, int(howmany / delta_d))); spdlog::drop(log->name()); } @@ -191,8 +191,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, int(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, int(howmany / delta_d))); spdlog::drop(log->name()); } diff --git a/example/example.cpp b/example/example.cpp index 93a7e0b4..6ba5c4c7 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -323,6 +323,6 @@ void file_events_example() }; handlers.after_close = [](spdlog::filename_t filename) { spdlog::info("After closing {}", filename); }; auto file_sink = std::make_shared("logs/events-sample.txt", true, handlers); - spdlog::logger my_logger("some_logger", file_sink); + spdlog::logger my_logger("some_logger", file_sink); my_logger.info("Some log line"); } diff --git a/include/spdlog/async.h b/include/spdlog/async.h index 6406822c..e54fedc6 100644 --- a/include/spdlog/async.h +++ b/include/spdlog/async.h @@ -35,7 +35,7 @@ template struct async_factory_impl { template - static std::shared_ptr create(std::string logger_name, SinkArgs &&...args) + static std::shared_ptr create(std::string logger_name, SinkArgs &&... args) { auto ®istry_inst = details::registry::instance(); @@ -61,13 +61,13 @@ using async_factory = async_factory_impl; using async_factory_nonblock = async_factory_impl; template -inline std::shared_ptr create_async(std::string logger_name, SinkArgs &&...sink_args) +inline std::shared_ptr create_async(std::string logger_name, SinkArgs &&... sink_args) { return async_factory::create(std::move(logger_name), std::forward(sink_args)...); } template -inline std::shared_ptr create_async_nb(std::string logger_name, SinkArgs &&...sink_args) +inline std::shared_ptr create_async_nb(std::string logger_name, SinkArgs &&... sink_args) { return async_factory_nonblock::create(std::move(logger_name), std::forward(sink_args)...); } diff --git a/include/spdlog/common.h b/include/spdlog/common.h index fdfff8c1..c7f7e46d 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -323,7 +323,7 @@ namespace details { using std::make_unique; #else template -std::unique_ptr make_unique(Args &&...args) +std::unique_ptr make_unique(Args &&... args) { static_assert(!std::is_array::value, "arrays not supported"); return std::unique_ptr(new T(std::forward(args)...)); diff --git a/include/spdlog/details/file_helper-inl.h b/include/spdlog/details/file_helper-inl.h index 63d511c6..8276633b 100644 --- a/include/spdlog/details/file_helper-inl.h +++ b/include/spdlog/details/file_helper-inl.h @@ -20,7 +20,7 @@ namespace spdlog { namespace details { -SPDLOG_INLINE file_helper::file_helper(const file_event_handlers& event_handlers) +SPDLOG_INLINE file_helper::file_helper(const file_event_handlers &event_handlers) : event_handlers_(event_handlers) {} diff --git a/include/spdlog/details/file_helper.h b/include/spdlog/details/file_helper.h index 69c5afdc..0f5988b9 100644 --- a/include/spdlog/details/file_helper.h +++ b/include/spdlog/details/file_helper.h @@ -17,7 +17,7 @@ class SPDLOG_API file_helper { public: file_helper() = default; - explicit file_helper(const file_event_handlers& event_handlers); + explicit file_helper(const file_event_handlers &event_handlers); file_helper(const file_helper &) = delete; file_helper &operator=(const file_helper &) = delete; diff --git a/include/spdlog/details/fmt_helper.h b/include/spdlog/details/fmt_helper.h index cc59dd62..1a60bc0d 100644 --- a/include/spdlog/details/fmt_helper.h +++ b/include/spdlog/details/fmt_helper.h @@ -9,8 +9,8 @@ #include #ifdef SPDLOG_USE_STD_FORMAT -#include -#include +# include +# include #endif // Some fmt helpers to efficiently format and pad ints and strings @@ -89,11 +89,11 @@ inline unsigned int count_digits(T n) return static_cast(fmt:: // fmt 7.0.0 renamed the internal namespace to detail. // See: https://github.com/fmtlib/fmt/issues/1538 -#if FMT_VERSION < 70000 +# if FMT_VERSION < 70000 internal -#else +# else detail -#endif +# endif ::count_digits(static_cast(n))); #endif } diff --git a/include/spdlog/details/os-inl.h b/include/spdlog/details/os-inl.h index e4cddd41..0575d811 100644 --- a/include/spdlog/details/os-inl.h +++ b/include/spdlog/details/os-inl.h @@ -381,11 +381,11 @@ SPDLOG_INLINE std::string filename_to_str(const filename_t &filename) { memory_buf_t buf; wstr_to_utf8buf(filename, buf); -#ifdef SPDLOG_USE_STD_FORMAT +# ifdef SPDLOG_USE_STD_FORMAT return buf; -#else +# else return fmt::to_string(buf); -#endif +# endif } #else SPDLOG_INLINE std::string filename_to_str(const filename_t &filename) diff --git a/include/spdlog/details/synchronous_factory.h b/include/spdlog/details/synchronous_factory.h index e1e42268..1f729ab9 100644 --- a/include/spdlog/details/synchronous_factory.h +++ b/include/spdlog/details/synchronous_factory.h @@ -13,7 +13,7 @@ class logger; struct synchronous_factory { template - static std::shared_ptr create(std::string logger_name, SinkArgs &&...args) + static std::shared_ptr create(std::string logger_name, SinkArgs &&... args) { auto sink = std::make_shared(std::forward(args)...); auto new_logger = std::make_shared(std::move(logger_name), std::move(sink)); diff --git a/include/spdlog/details/tcp_client-windows.h b/include/spdlog/details/tcp_client-windows.h index b331a500..9d3647aa 100644 --- a/include/spdlog/details/tcp_client-windows.h +++ b/include/spdlog/details/tcp_client-windows.h @@ -24,7 +24,7 @@ namespace details { class tcp_client { SOCKET socket_ = INVALID_SOCKET; - + static void init_winsock_() { WSADATA wsaData; @@ -55,7 +55,6 @@ public: close(); ::WSACleanup(); } - bool is_connected() const { @@ -65,7 +64,7 @@ public: void close() { ::closesocket(socket_); - socket_ = INVALID_SOCKET; + socket_ = INVALID_SOCKET; } SOCKET fd() const @@ -73,10 +72,9 @@ public: return socket_; } - // try to connect or throw on failure void connect(const std::string &host, int port) - { + { if (is_connected()) { close(); diff --git a/include/spdlog/details/udp_client-windows.h b/include/spdlog/details/udp_client-windows.h index 372efa6d..d67c7258 100644 --- a/include/spdlog/details/udp_client-windows.h +++ b/include/spdlog/details/udp_client-windows.h @@ -23,7 +23,7 @@ namespace spdlog { namespace details { class udp_client { - static constexpr int TX_BUFFER_SIZE = 1024*10; + static constexpr int TX_BUFFER_SIZE = 1024 * 10; SOCKET socket_ = INVALID_SOCKET; sockaddr_in addr_ = {0}; @@ -64,7 +64,8 @@ public: addr_.sin_family = PF_INET; addr_.sin_port = htons(port); addr_.sin_addr.s_addr = INADDR_ANY; - if (InetPton(PF_INET, TEXT(host.c_str()), &addr_.sin_addr.s_addr) != 1) { + if (InetPton(PF_INET, TEXT(host.c_str()), &addr_.sin_addr.s_addr) != 1) + { int last_error = ::WSAGetLastError(); ::WSACleanup(); throw_winsock_error_("error: Invalid address!", last_error); diff --git a/include/spdlog/details/udp_client.h b/include/spdlog/details/udp_client.h index 7a8ee9cc..2db5b89e 100644 --- a/include/spdlog/details/udp_client.h +++ b/include/spdlog/details/udp_client.h @@ -31,7 +31,6 @@ class udp_client int socket_ = -1; struct sockaddr_in sockAddr_; - void cleanup_() { if (socket_ != -1) @@ -59,8 +58,9 @@ public: sockAddr_.sin_family = AF_INET; sockAddr_.sin_port = htons(port); - - if (::inet_aton(host.c_str(), &sockAddr_.sin_addr) == 0) { + + if (::inet_aton(host.c_str(), &sockAddr_.sin_addr) == 0) + { cleanup_(); throw_spdlog_ex("error: Invalid address!"); } @@ -85,7 +85,7 @@ public: ssize_t toslen = 0; socklen_t tolen = sizeof(struct sockaddr); if ((toslen = ::sendto(socket_, data, n_bytes, 0, (struct sockaddr *)&sockAddr_, tolen)) == -1) - { + { throw_spdlog_ex("sendto(2) failed", errno); } } diff --git a/include/spdlog/fmt/bin_to_hex.h b/include/spdlog/fmt/bin_to_hex.h index 835e4f07..c6ed08d8 100644 --- a/include/spdlog/fmt/bin_to_hex.h +++ b/include/spdlog/fmt/bin_to_hex.h @@ -220,4 +220,4 @@ struct formatter, char> } } }; -} // namespace fmt/std +} // namespace std diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index 4ce41b84..a8abae41 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -31,9 +31,9 @@ # define SPDLOG_LOGGER_CATCH(location) \ catch (const std::exception &ex) \ { \ - if(location.filename) \ + if (location.filename) \ { \ - err_handler_(fmt_lib::format("{} [{}({})]", ex.what(), location.filename, location.line)); \ + err_handler_(fmt_lib::format("{} [{}({})]", ex.what(), location.filename, location.line)); \ } \ else \ { \ @@ -85,13 +85,13 @@ public: void swap(spdlog::logger &other) SPDLOG_NOEXCEPT; template - void log(source_loc loc, level::level_enum lvl, format_string_t fmt, Args &&...args) + void log(source_loc loc, level::level_enum lvl, format_string_t fmt, Args &&... args) { log_(loc, lvl, fmt, std::forward(args)...); } template - void log(level::level_enum lvl, format_string_t fmt, Args &&...args) + void log(level::level_enum lvl, format_string_t fmt, Args &&... args) { log(source_loc{}, lvl, fmt, std::forward(args)...); } @@ -141,50 +141,50 @@ public: } template - void trace(format_string_t fmt, Args &&...args) + void trace(format_string_t fmt, Args &&... args) { log(level::trace, fmt, std::forward(args)...); } template - void debug(format_string_t fmt, Args &&...args) + void debug(format_string_t fmt, Args &&... args) { log(level::debug, fmt, std::forward(args)...); } template - void info(format_string_t fmt, Args &&...args) + void info(format_string_t fmt, Args &&... args) { log(level::info, fmt, std::forward(args)...); } template - void warn(format_string_t fmt, Args &&...args) + void warn(format_string_t fmt, Args &&... args) { log(level::warn, fmt, std::forward(args)...); } template - void error(format_string_t fmt, Args &&...args) + void error(format_string_t fmt, Args &&... args) { log(level::err, fmt, std::forward(args)...); } template - void critical(format_string_t fmt, Args &&...args) + void critical(format_string_t fmt, Args &&... args) { log(level::critical, fmt, std::forward(args)...); } #ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT template - void log(source_loc loc, level::level_enum lvl, wformat_string_t fmt, Args &&...args) + void log(source_loc loc, level::level_enum lvl, wformat_string_t fmt, Args &&... args) { log_(loc, lvl, fmt, std::forward(args)...); } template - void log(level::level_enum lvl, wformat_string_t fmt, Args &&...args) + void log(level::level_enum lvl, wformat_string_t fmt, Args &&... args) { log(source_loc{}, lvl, fmt, std::forward(args)...); } @@ -225,37 +225,37 @@ public: } template - void trace(wformat_string_t fmt, Args &&...args) + void trace(wformat_string_t fmt, Args &&... args) { log(level::trace, fmt, std::forward(args)...); } template - void debug(wformat_string_t fmt, Args &&...args) + void debug(wformat_string_t fmt, Args &&... args) { log(level::debug, fmt, std::forward(args)...); } template - void info(wformat_string_t fmt, Args &&...args) + void info(wformat_string_t fmt, Args &&... args) { log(level::info, fmt, std::forward(args)...); } template - void warn(wformat_string_t fmt, Args &&...args) + void warn(wformat_string_t fmt, Args &&... args) { log(level::warn, fmt, std::forward(args)...); } template - void error(wformat_string_t fmt, Args &&...args) + void error(wformat_string_t fmt, Args &&... args) { log(level::err, fmt, std::forward(args)...); } template - void critical(wformat_string_t fmt, Args &&...args) + void critical(wformat_string_t fmt, Args &&... args) { log(level::critical, fmt, std::forward(args)...); } @@ -353,7 +353,7 @@ protected: // common implementation for after templated public api has been resolved template - void log_(source_loc loc, level::level_enum lvl, string_view_t fmt, Args &&...args) + void log_(source_loc loc, level::level_enum lvl, string_view_t fmt, Args &&... args) { bool log_enabled = should_log(lvl); bool traceback_enabled = tracer_.enabled(); @@ -377,7 +377,7 @@ protected: #ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT template - void log_(source_loc loc, level::level_enum lvl, wstring_view_t fmt, Args &&...args) + void log_(source_loc loc, level::level_enum lvl, wstring_view_t fmt, Args &&... args) { bool log_enabled = should_log(lvl); bool traceback_enabled = tracer_.enabled(); @@ -389,12 +389,12 @@ protected: { // format to wmemory_buffer and convert to utf8 ; -#ifdef SPDLOG_USE_STD_FORMAT +# ifdef SPDLOG_USE_STD_FORMAT wmemory_buf_t wbuf = std::vformat(fmt, std::make_wformat_args(std::forward(args)...)); -#else +# else wmemory_buf_t wbuf; fmt::detail::vformat_to(wbuf, fmt, fmt::make_format_args(std::forward(args)...)); -#endif +# endif memory_buf_t buf; details::os::wstr_to_utf8buf(wstring_view_t(wbuf.data(), wbuf.size()), buf); details::log_msg log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size())); diff --git a/include/spdlog/pattern_formatter.h b/include/spdlog/pattern_formatter.h index e9ccfaa7..147d8546 100644 --- a/include/spdlog/pattern_formatter.h +++ b/include/spdlog/pattern_formatter.h @@ -92,7 +92,7 @@ public: void format(const details::log_msg &msg, memory_buf_t &dest) override; template - pattern_formatter &add_flag(char flag, Args &&...args) + pattern_formatter &add_flag(char flag, Args &&... args) { custom_handlers_[flag] = details::make_unique(std::forward(args)...); return *this; diff --git a/include/spdlog/sinks/basic_file_sink-inl.h b/include/spdlog/sinks/basic_file_sink-inl.h index af383214..8d23f96d 100644 --- a/include/spdlog/sinks/basic_file_sink-inl.h +++ b/include/spdlog/sinks/basic_file_sink-inl.h @@ -14,7 +14,7 @@ namespace spdlog { namespace sinks { template -SPDLOG_INLINE basic_file_sink::basic_file_sink(const filename_t &filename, bool truncate, const file_event_handlers& event_handlers) +SPDLOG_INLINE 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/include/spdlog/sinks/basic_file_sink.h b/include/spdlog/sinks/basic_file_sink.h index 12cd95ef..aacc993b 100644 --- a/include/spdlog/sinks/basic_file_sink.h +++ b/include/spdlog/sinks/basic_file_sink.h @@ -20,7 +20,7 @@ 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: @@ -40,13 +40,15 @@ using basic_file_sink_st = basic_file_sink; // factory functions // template -inline std::shared_ptr basic_logger_mt(const std::string &logger_name, const filename_t &filename, bool truncate = false, const file_event_handlers& event_handlers = {}) +inline std::shared_ptr basic_logger_mt( + const std::string &logger_name, const filename_t &filename, bool truncate = false, const file_event_handlers &event_handlers = {}) { return Factory::template create(logger_name, filename, truncate, event_handlers); } template -inline std::shared_ptr basic_logger_st(const std::string &logger_name, const filename_t &filename, bool truncate = false, const file_event_handlers& event_handlers = {}) +inline std::shared_ptr basic_logger_st( + const std::string &logger_name, const filename_t &filename, bool truncate = false, const file_event_handlers &event_handlers = {}) { return Factory::template create(logger_name, filename, truncate, event_handlers); } diff --git a/include/spdlog/sinks/daily_file_sink.h b/include/spdlog/sinks/daily_file_sink.h index c0f896a1..bb566e18 100644 --- a/include/spdlog/sinks/daily_file_sink.h +++ b/include/spdlog/sinks/daily_file_sink.h @@ -72,7 +72,7 @@ struct daily_filename_format_calculator } buf.resize(buf.size() * 2); } - + return buf; #else // generate fmt datetime format string, e.g. {:%Y-%m-%d}. @@ -116,7 +116,8 @@ class daily_file_sink final : public base_sink { public: // create daily file sink which rotates on given time - daily_file_sink(filename_t base_filename, int rotation_hour, int rotation_minute, bool truncate = false, uint16_t max_files = 0, const file_event_handlers& event_handlers = {}) + daily_file_sink(filename_t base_filename, int rotation_hour, int rotation_minute, bool truncate = false, uint16_t max_files = 0, + const file_event_handlers &event_handlers = {}) : base_filename_(std::move(base_filename)) , rotation_h_(rotation_hour) , rotation_m_(rotation_minute) @@ -262,30 +263,32 @@ using daily_file_format_sink_st = daily_file_sink -inline std::shared_ptr daily_logger_mt( - const std::string &logger_name, const filename_t &filename, int hour = 0, int minute = 0, bool truncate = false, uint16_t max_files = 0, const file_event_handlers& event_handlers = {}) +inline std::shared_ptr daily_logger_mt(const std::string &logger_name, const filename_t &filename, int hour = 0, int minute = 0, + 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); } template -inline std::shared_ptr daily_logger_format_mt( - const std::string &logger_name, const filename_t &filename, int hour = 0, int minute = 0, bool truncate = false, uint16_t max_files = 0, const file_event_handlers& event_handlers = {}) +inline std::shared_ptr daily_logger_format_mt(const std::string &logger_name, const filename_t &filename, int hour = 0, + int minute = 0, 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 -inline std::shared_ptr daily_logger_st( - const std::string &logger_name, const filename_t &filename, int hour = 0, int minute = 0, bool truncate = false, uint16_t max_files = 0, const file_event_handlers& event_handlers = {}) +inline std::shared_ptr daily_logger_st(const std::string &logger_name, const filename_t &filename, int hour = 0, int minute = 0, + 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); } template -inline std::shared_ptr daily_logger_format_st( - const std::string &logger_name, const filename_t &filename, int hour = 0, int minute = 0, bool truncate = false, uint16_t max_files = 0, const file_event_handlers& event_handlers = {}) +inline std::shared_ptr daily_logger_format_st(const std::string &logger_name, const filename_t &filename, int hour = 0, + int minute = 0, 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/hourly_file_sink.h b/include/spdlog/sinks/hourly_file_sink.h index 7a7c715c..029e7b1d 100644 --- a/include/spdlog/sinks/hourly_file_sink.h +++ b/include/spdlog/sinks/hourly_file_sink.h @@ -46,7 +46,8 @@ class hourly_file_sink final : public base_sink { public: // create hourly file sink which rotates on given time - hourly_file_sink(filename_t base_filename, bool truncate = false, uint16_t max_files = 0, const file_event_handlers& event_handlers = {}) + hourly_file_sink( + filename_t base_filename, bool truncate = false, uint16_t max_files = 0, const file_event_handlers &event_handlers = {}) : base_filename_(std::move(base_filename)) , file_helper_{event_handlers} , truncate_(truncate) @@ -180,15 +181,15 @@ using hourly_file_sink_st = hourly_file_sink; // factory functions // template -inline std::shared_ptr hourly_logger_mt( - const std::string &logger_name, const filename_t &filename, bool truncate = false, uint16_t max_files = 0, const file_event_handlers& event_handlers = {}) +inline std::shared_ptr hourly_logger_mt(const std::string &logger_name, const filename_t &filename, 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); } template -inline std::shared_ptr hourly_logger_st( - const std::string &logger_name, const filename_t &filename, bool truncate = false, uint16_t max_files = 0, const file_event_handlers& event_handlers = {}) +inline std::shared_ptr hourly_logger_st(const std::string &logger_name, const filename_t &filename, 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); } diff --git a/include/spdlog/sinks/msvc_sink.h b/include/spdlog/sinks/msvc_sink.h index 76ec40a0..cf2516d7 100644 --- a/include/spdlog/sinks/msvc_sink.h +++ b/include/spdlog/sinks/msvc_sink.h @@ -30,11 +30,11 @@ protected: { memory_buf_t formatted; base_sink::formatter_->format(msg, formatted); -#ifdef SPDLOG_USE_STD_FORMAT +# ifdef SPDLOG_USE_STD_FORMAT OutputDebugStringA(formatted.c_str()); -#else +# else OutputDebugStringA(fmt::to_string(formatted).c_str()); -#endif +# endif } void flush_() override {} diff --git a/include/spdlog/sinks/qt_sinks.h b/include/spdlog/sinks/qt_sinks.h index 99545665..31b49c60 100644 --- a/include/spdlog/sinks/qt_sinks.h +++ b/include/spdlog/sinks/qt_sinks.h @@ -21,29 +21,36 @@ // namespace spdlog { namespace sinks { -template class qt_sink : public base_sink { +template +class qt_sink : public base_sink +{ public: - qt_sink(QObject *qt_object, const std::string &meta_method) { - qt_object_ = qt_object; - meta_method_ = meta_method; - } + qt_sink(QObject *qt_object, const std::string &meta_method) + { + qt_object_ = qt_object; + meta_method_ = meta_method; + } - ~qt_sink() { flush_(); } + ~qt_sink() + { + flush_(); + } protected: - void sink_it_(const details::log_msg &msg) override { - memory_buf_t formatted; - base_sink::formatter_->format(msg, formatted); - 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())); - } + void sink_it_(const details::log_msg &msg) override + { + memory_buf_t formatted; + base_sink::formatter_->format(msg, formatted); + 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())); + } - void flush_() override {} + void flush_() override {} private: - QObject *qt_object_ = nullptr; - std::string meta_method_; + QObject *qt_object_ = nullptr; + std::string meta_method_; }; #include "spdlog/details/null_mutex.h" @@ -55,39 +62,41 @@ using qt_sink_st = qt_sink; // // Factory functions // -template -inline std::shared_ptr -qt_logger_mt(const std::string &logger_name, QTextEdit* qt_object, const std::string &meta_method = "append") { - return Factory::template create(logger_name, qt_object, meta_method); -} - -template -inline std::shared_ptr -qt_logger_st(const std::string &logger_name, QTextEdit* qt_object, const std::string &meta_method = "append") { - return Factory::template create(logger_name, qt_object, meta_method); -} - -template -inline std::shared_ptr -qt_logger_mt(const std::string &logger_name, QPlainTextEdit* qt_object , const std::string &meta_method = "appendPlainText") { +template +inline std::shared_ptr qt_logger_mt(const std::string &logger_name, QTextEdit *qt_object, const std::string &meta_method = "append") +{ return Factory::template create(logger_name, qt_object, meta_method); } -template -inline std::shared_ptr -qt_logger_st(const std::string &logger_name, QPlainTextEdit* qt_object, const std::string &meta_method = "appendPlainText") { +template +inline std::shared_ptr qt_logger_st(const std::string &logger_name, QTextEdit *qt_object, const std::string &meta_method = "append") +{ return Factory::template create(logger_name, qt_object, meta_method); } -template -inline std::shared_ptr -qt_logger_mt(const std::string &logger_name, QObject* qt_object, const std::string &meta_method) { +template +inline std::shared_ptr qt_logger_mt( + const std::string &logger_name, QPlainTextEdit *qt_object, const std::string &meta_method = "appendPlainText") +{ 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) { +template +inline std::shared_ptr qt_logger_st( + const std::string &logger_name, QPlainTextEdit *qt_object, const std::string &meta_method = "appendPlainText") +{ + return Factory::template create(logger_name, qt_object, meta_method); +} + +template +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) +{ return Factory::template create(logger_name, qt_object, meta_method); } } // namespace spdlog diff --git a/include/spdlog/sinks/rotating_file_sink-inl.h b/include/spdlog/sinks/rotating_file_sink-inl.h index 8555d0d2..2c003959 100644 --- a/include/spdlog/sinks/rotating_file_sink-inl.h +++ b/include/spdlog/sinks/rotating_file_sink-inl.h @@ -25,7 +25,7 @@ namespace sinks { template SPDLOG_INLINE rotating_file_sink::rotating_file_sink( - filename_t base_filename, std::size_t max_size, std::size_t max_files, bool rotate_on_open, const file_event_handlers& event_handlers) + filename_t base_filename, std::size_t max_size, std::size_t max_files, bool rotate_on_open, const file_event_handlers &event_handlers) : base_filename_(std::move(base_filename)) , max_size_(max_size) , max_files_(max_files) diff --git a/include/spdlog/sinks/rotating_file_sink.h b/include/spdlog/sinks/rotating_file_sink.h index d34ec02e..ce0d7b1e 100644 --- a/include/spdlog/sinks/rotating_file_sink.h +++ b/include/spdlog/sinks/rotating_file_sink.h @@ -22,7 +22,8 @@ template class rotating_file_sink final : public base_sink { public: - rotating_file_sink(filename_t base_filename, std::size_t max_size, std::size_t max_files, bool rotate_on_open = false, const file_event_handlers& event_handlers = {}); + rotating_file_sink(filename_t base_filename, std::size_t max_size, std::size_t max_files, bool rotate_on_open = false, + const file_event_handlers &event_handlers = {}); static filename_t calc_filename(const filename_t &filename, std::size_t index); filename_t filename(); @@ -59,17 +60,19 @@ using rotating_file_sink_st = rotating_file_sink; // template -inline std::shared_ptr rotating_logger_mt( - const std::string &logger_name, const filename_t &filename, size_t max_file_size, size_t max_files, bool rotate_on_open = false, const file_event_handlers& event_handlers = {}) +inline std::shared_ptr rotating_logger_mt(const std::string &logger_name, const filename_t &filename, size_t max_file_size, + 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 -inline std::shared_ptr rotating_logger_st( - const std::string &logger_name, const filename_t &filename, size_t max_file_size, size_t max_files, bool rotate_on_open = false, const file_event_handlers& event_handlers = {}) +inline std::shared_ptr rotating_logger_st(const std::string &logger_name, const filename_t &filename, size_t max_file_size, + 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/udp_sink.h b/include/spdlog/sinks/udp_sink.h index 934f6686..ccbce2be 100644 --- a/include/spdlog/sinks/udp_sink.h +++ b/include/spdlog/sinks/udp_sink.h @@ -53,7 +53,7 @@ protected: client_.send(formatted.data(), formatted.size()); } - void flush_() override {} + void flush_() override {} details::udp_client client_; }; diff --git a/include/spdlog/sinks/win_eventlog_sink.h b/include/spdlog/sinks/win_eventlog_sink.h index 202c79f8..8a978a09 100644 --- a/include/spdlog/sinks/win_eventlog_sink.h +++ b/include/spdlog/sinks/win_eventlog_sink.h @@ -53,8 +53,8 @@ struct local_alloc_t SPDLOG_CONSTEXPR local_alloc_t() SPDLOG_NOEXCEPT : hlocal_(nullptr) {} - local_alloc_t(local_alloc_t const&) = delete; - local_alloc_t& operator=(local_alloc_t const&) = delete; + local_alloc_t(local_alloc_t const &) = delete; + local_alloc_t &operator=(local_alloc_t const &) = delete; ~local_alloc_t() SPDLOG_NOEXCEPT { diff --git a/include/spdlog/spdlog.h b/include/spdlog/spdlog.h index 327a0ebe..65d3e9d5 100644 --- a/include/spdlog/spdlog.h +++ b/include/spdlog/spdlog.h @@ -31,7 +31,7 @@ using default_factory = synchronous_factory; // Example: // spdlog::create("logger_name", "dailylog_filename", 11, 59); template -inline std::shared_ptr create(std::string logger_name, SinkArgs &&...sink_args) +inline std::shared_ptr create(std::string logger_name, SinkArgs &&... sink_args) { return default_factory::create(std::move(logger_name), std::forward(sink_args)...); } @@ -128,49 +128,49 @@ SPDLOG_API spdlog::logger *default_logger_raw(); SPDLOG_API void set_default_logger(std::shared_ptr default_logger); template -inline void log(source_loc source, level::level_enum lvl, format_string_t fmt, Args &&...args) +inline void log(source_loc source, level::level_enum lvl, format_string_t fmt, Args &&... args) { default_logger_raw()->log(source, lvl, fmt, std::forward(args)...); } template -inline void log(level::level_enum lvl, format_string_t fmt, Args &&...args) +inline void log(level::level_enum lvl, format_string_t fmt, Args &&... args) { default_logger_raw()->log(source_loc{}, lvl, fmt, std::forward(args)...); } template -inline void trace(format_string_t fmt, Args &&...args) +inline void trace(format_string_t fmt, Args &&... args) { default_logger_raw()->trace(fmt, std::forward(args)...); } template -inline void debug(format_string_t fmt, Args &&...args) +inline void debug(format_string_t fmt, Args &&... args) { default_logger_raw()->debug(fmt, std::forward(args)...); } template -inline void info(format_string_t fmt, Args &&...args) +inline void info(format_string_t fmt, Args &&... args) { default_logger_raw()->info(fmt, std::forward(args)...); } template -inline void warn(format_string_t fmt, Args &&...args) +inline void warn(format_string_t fmt, Args &&... args) { default_logger_raw()->warn(fmt, std::forward(args)...); } template -inline void error(format_string_t fmt, Args &&...args) +inline void error(format_string_t fmt, Args &&... args) { default_logger_raw()->error(fmt, std::forward(args)...); } template -inline void critical(format_string_t fmt, Args &&...args) +inline void critical(format_string_t fmt, Args &&... args) { default_logger_raw()->critical(fmt, std::forward(args)...); } @@ -189,49 +189,49 @@ inline void log(level::level_enum lvl, const T &msg) #ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT template -inline void log(source_loc source, level::level_enum lvl, wformat_string_t fmt, Args &&...args) +inline void log(source_loc source, level::level_enum lvl, wformat_string_t fmt, Args &&... args) { default_logger_raw()->log(source, lvl, fmt, std::forward(args)...); } template -inline void log(level::level_enum lvl, wformat_string_t fmt, Args &&...args) +inline void log(level::level_enum lvl, wformat_string_t fmt, Args &&... args) { default_logger_raw()->log(source_loc{}, lvl, fmt, std::forward(args)...); } template -inline void trace(wformat_string_t fmt, Args &&...args) +inline void trace(wformat_string_t fmt, Args &&... args) { default_logger_raw()->trace(fmt, std::forward(args)...); } template -inline void debug(wformat_string_t fmt, Args &&...args) +inline void debug(wformat_string_t fmt, Args &&... args) { default_logger_raw()->debug(fmt, std::forward(args)...); } template -inline void info(wformat_string_t fmt, Args &&...args) +inline void info(wformat_string_t fmt, Args &&... args) { default_logger_raw()->info(fmt, std::forward(args)...); } template -inline void warn(wformat_string_t fmt, Args &&...args) +inline void warn(wformat_string_t fmt, Args &&... args) { default_logger_raw()->warn(fmt, std::forward(args)...); } template -inline void error(wformat_string_t fmt, Args &&...args) +inline void error(wformat_string_t fmt, Args &&... args) { default_logger_raw()->error(fmt, std::forward(args)...); } template -inline void critical(wformat_string_t fmt, Args &&...args) +inline void critical(wformat_string_t fmt, Args &&... args) { default_logger_raw()->critical(fmt, std::forward(args)...); } diff --git a/include/spdlog/stopwatch.h b/include/spdlog/stopwatch.h index a1542b2d..4e62259b 100644 --- a/include/spdlog/stopwatch.h +++ b/include/spdlog/stopwatch.h @@ -65,4 +65,4 @@ struct formatter : formatter return formatter::format(sw.elapsed().count(), ctx); } }; -} // namespace fmt/std +} // namespace std diff --git a/tests/test_daily_logger.cpp b/tests/test_daily_logger.cpp index 66f01a46..09f7c0e5 100644 --- a/tests/test_daily_logger.cpp +++ b/tests/test_daily_logger.cpp @@ -33,17 +33,17 @@ TEST_CASE("daily_logger with dateonly calculator", "[daily_logger]") #ifdef SPDLOG_WCHAR_FILENAMES spdlog::memory_buf_t buf; spdlog::details::os::wstr_to_utf8buf(fmt::to_string(w), buf); -#ifdef SPDLOG_USE_STD_FORMAT +# ifdef SPDLOG_USE_STD_FORMAT auto &filename = buf; -#else +# else auto filename = fmt::to_string(buf); -#endif +# endif #else -#ifdef SPDLOG_USE_STD_FORMAT +# ifdef SPDLOG_USE_STD_FORMAT auto &filename = w; -#else +# else auto filename = fmt::to_string(w); -#endif +# endif #endif require_message_count(filename, 10); } @@ -53,8 +53,8 @@ struct custom_daily_file_name_calculator static spdlog::filename_t calc_filename(const spdlog::filename_t &basename, const tm &now_tm) { filename_memory_buf_t w; - spdlog::fmt_lib::format_to(std::back_inserter(w), SPDLOG_FILENAME_T("{}{:04d}{:02d}{:02d}"), basename, now_tm.tm_year + 1900, now_tm.tm_mon + 1, - now_tm.tm_mday); + spdlog::fmt_lib::format_to(std::back_inserter(w), SPDLOG_FILENAME_T("{}{:04d}{:02d}{:02d}"), basename, now_tm.tm_year + 1900, + now_tm.tm_mon + 1, now_tm.tm_mday); #ifdef SPDLOG_USE_STD_FORMAT return w; #else @@ -87,17 +87,17 @@ TEST_CASE("daily_logger with custom calculator", "[daily_logger]") #ifdef SPDLOG_WCHAR_FILENAMES spdlog::memory_buf_t buf; spdlog::details::os::wstr_to_utf8buf(fmt::to_string(w), buf); -#ifdef SPDLOG_USE_STD_FORMAT +# ifdef SPDLOG_USE_STD_FORMAT auto &filename = buf; -#else +# else auto filename = fmt::to_string(buf); -#endif +# endif #else -#ifdef SPDLOG_USE_STD_FORMAT +# ifdef SPDLOG_USE_STD_FORMAT auto &filename = w; -#else +# else auto filename = fmt::to_string(w); -#endif +# endif #endif require_message_count(filename, 10); } @@ -146,10 +146,10 @@ 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_pattern_formatter.cpp b/tests/test_pattern_formatter.cpp index 78c4cd30..02a1bc2b 100644 --- a/tests/test_pattern_formatter.cpp +++ b/tests/test_pattern_formatter.cpp @@ -5,7 +5,7 @@ using spdlog::memory_buf_t; // log to str and return it template -static std::string log_to_str(const std::string &msg, const Args &...args) +static std::string log_to_str(const std::string &msg, const Args &... args) { std::ostringstream oss; auto oss_sink = std::make_shared(oss);