From f5831d5132cf50696bf16b663202c3d4b2a2ee78 Mon Sep 17 00:00:00 2001 From: gabime Date: Fri, 5 Jul 2019 10:45:37 +0300 Subject: [PATCH] clang-format --- include/spdlog/sinks/stdout_sinks.h | 1 - include/spdlog/sinks/syslog_sink.h | 16 ++++++------ include/spdlog/sinks/systemd_sink.h | 39 +++++++++++------------------ src/spdlog.cpp | 1 - tests/test_pattern_formatter.cpp | 7 ++---- 5 files changed, 23 insertions(+), 41 deletions(-) diff --git a/include/spdlog/sinks/stdout_sinks.h b/include/spdlog/sinks/stdout_sinks.h index 18971107..36c2f3cd 100644 --- a/include/spdlog/sinks/stdout_sinks.h +++ b/include/spdlog/sinks/stdout_sinks.h @@ -72,4 +72,3 @@ std::shared_ptr stderr_logger_st(const std::string &logger_name); } // namespace spdlog #include "stdout_sinks-inl.h" - diff --git a/include/spdlog/sinks/syslog_sink.h b/include/spdlog/sinks/syslog_sink.h index efd6b5d2..5f690d3d 100644 --- a/include/spdlog/sinks/syslog_sink.h +++ b/include/spdlog/sinks/syslog_sink.h @@ -22,15 +22,13 @@ class syslog_sink : public base_sink public: syslog_sink(std::string ident, int syslog_option, int syslog_facility, bool enable_formatting) : enable_formatting_{enable_formatting} - , syslog_levels_{ - /* spdlog::level::trace */ LOG_DEBUG, - /* spdlog::level::debug */ LOG_DEBUG, - /* spdlog::level::info */ LOG_INFO, - /* spdlog::level::warn */ LOG_WARNING, - /* spdlog::level::err */ LOG_ERR, - /* spdlog::level::critical */ LOG_CRIT, - /* spdlog::level::off */ LOG_INFO - } + , syslog_levels_{/* spdlog::level::trace */ LOG_DEBUG, + /* spdlog::level::debug */ LOG_DEBUG, + /* spdlog::level::info */ LOG_INFO, + /* spdlog::level::warn */ LOG_WARNING, + /* spdlog::level::err */ LOG_ERR, + /* spdlog::level::critical */ LOG_CRIT, + /* spdlog::level::off */ LOG_INFO} , ident_{std::move(ident)} { // set ident to be program name if empty diff --git a/include/spdlog/sinks/systemd_sink.h b/include/spdlog/sinks/systemd_sink.h index 23f9e5b3..eeb56bae 100644 --- a/include/spdlog/sinks/systemd_sink.h +++ b/include/spdlog/sinks/systemd_sink.h @@ -12,7 +12,6 @@ namespace spdlog { namespace sinks { - /** * Sink that write to systemd journal using the `sd_journal_send()` library call. * @@ -23,15 +22,14 @@ class systemd_sink : public base_sink { public: // - systemd_sink(): syslog_levels_{ - /* spdlog::level::trace */ LOG_DEBUG, - /* spdlog::level::debug */ LOG_DEBUG, - /* spdlog::level::info */ LOG_INFO, - /* spdlog::level::warn */ LOG_WARNING, - /* spdlog::level::err */ LOG_ERR, - /* spdlog::level::critical */ LOG_CRIT, - /* spdlog::level::off */ LOG_INFO - } + systemd_sink() + : syslog_levels_{/* spdlog::level::trace */ LOG_DEBUG, + /* spdlog::level::debug */ LOG_DEBUG, + /* spdlog::level::info */ LOG_INFO, + /* spdlog::level::warn */ LOG_WARNING, + /* spdlog::level::err */ LOG_ERR, + /* spdlog::level::critical */ LOG_CRIT, + /* spdlog::level::off */ LOG_INFO} {} ~systemd_sink() override {} @@ -40,7 +38,6 @@ public: systemd_sink &operator=(const systemd_sink &) = delete; protected: - std::array syslog_levels_; void sink_it_(const details::log_msg &msg) override @@ -48,33 +45,25 @@ protected: int err; // Do not send source location if not available - if(msg.source.empty()) + if (msg.source.empty()) { // Note: function call inside '()' to avoid macro expansion err = (sd_journal_send)( - "MESSAGE=%.*s", static_cast(msg.payload.size()), msg.payload.data(), - "PRIORITY=%d", syslog_level(msg.level), - nullptr); + "MESSAGE=%.*s", static_cast(msg.payload.size()), msg.payload.data(), "PRIORITY=%d", syslog_level(msg.level), nullptr); } else { - err = (sd_journal_send)( - "MESSAGE=%.*s", static_cast(msg.payload.size()), msg.payload.data(), - "PRIORITY=%d", syslog_level(msg.level), - "SOURCE_FILE=%s", msg.source.filename, - "SOURCE_LINE=%d", msg.source.line, - "SOURCE_FUNC=%s", msg.source.funcname, - nullptr); + err = (sd_journal_send)("MESSAGE=%.*s", static_cast(msg.payload.size()), msg.payload.data(), "PRIORITY=%d", + syslog_level(msg.level), "SOURCE_FILE=%s", msg.source.filename, "SOURCE_LINE=%d", msg.source.line, "SOURCE_FUNC=%s", + msg.source.funcname, nullptr); } - if(err) + if (err) { throw spdlog_ex("Failed writing to systemd", errno); } - } - int syslog_level(level::level_enum l) { return syslog_levels_.at(static_cast(l)); diff --git a/src/spdlog.cpp b/src/spdlog.cpp index c41b4c33..39d775fd 100644 --- a/src/spdlog.cpp +++ b/src/spdlog.cpp @@ -80,7 +80,6 @@ template std::shared_ptr spdlog::stdout_color_st spdlog::stderr_color_mt(const std::string &logger_name, color_mode mode); template std::shared_ptr spdlog::stderr_color_st(const std::string &logger_name, color_mode mode); - // Slightly modified version of fmt lib's format.cc source file. // Copyright (c) 2012 - 2016, Victor Zverovich // All rights reserved. diff --git a/tests/test_pattern_formatter.cpp b/tests/test_pattern_formatter.cpp index 7b21b381..cda99071 100644 --- a/tests/test_pattern_formatter.cpp +++ b/tests/test_pattern_formatter.cpp @@ -181,19 +181,16 @@ TEST_CASE("center_padded_short", "[pattern_formatter]") TEST_CASE("left_padded_huge", "[pattern_formatter]") { - REQUIRE( - log_to_str("Some message", "[%-300n] %v", spdlog::pattern_time_type::local, "\n") == + REQUIRE(log_to_str("Some message", "[%-300n] %v", spdlog::pattern_time_type::local, "\n") == "[pattern_tester ] Some message\n"); } TEST_CASE("left_padded_max", "[pattern_formatter]") { - REQUIRE( - log_to_str("Some message", "[%-64n] %v", spdlog::pattern_time_type::local, "\n") == + REQUIRE(log_to_str("Some message", "[%-64n] %v", spdlog::pattern_time_type::local, "\n") == "[pattern_tester ] Some message\n"); } - TEST_CASE("clone-default-formatter", "[pattern_formatter]") { auto formatter_1 = std::make_shared();