Loading include/client/logging.hpp +3 −3 Changes for include/client/logging.hpp: 3 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -412,7 +412,7 @@ struct logger { template <typename... Args> inline void log(log_level level, const char* const func, const int lineno, Args&&... args) { fmt::string_view format, Args&&... args) { if(!(level & log_mask_)) { return; Loading @@ -437,8 +437,8 @@ struct logger { } try { fmt::format_to(std::back_inserter(buffer), std::forward<Args>(args)...); fmt::vformat_to(std::back_inserter(buffer), format, fmt::make_format_args(args...)); } catch(const fmt::format_error&) { // Logging must never terminate the intercepted application. This // fallback is especially important on failed RPC paths, where an Loading tests/unit/test_path.cpp +27 −0 Changes for tests/unit/test_path.cpp: 27 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -40,6 +40,33 @@ #include <catch2/catch_all.hpp> #include <client/path.hpp> #include <client/preload.hpp> #include <client/logging.hpp> #include "helpers/helpers.hpp" TEST_CASE("client logger accepts runtime formats", "[logging]") { helpers::temporary_directory directory; const auto path = directory.dirname() / "client.log"; { gkfs::log::logger logger("info", path.string(), false, true #ifdef GKFS_DEBUG_BUILD , "", 0 #endif ); const std::string format = "runtime {}"; logger.log(gkfs::log::info, __func__, __LINE__, "literal {}", 42); logger.log(gkfs::log::info, __func__, __LINE__, format, 43); logger.log(gkfs::log::info, __func__, __LINE__, "no arguments"); REQUIRE_NOTHROW(logger.log(gkfs::log::info, __func__, __LINE__, "malformed {")); } std::string contents; helpers::load_string_file(path, contents); REQUIRE(contents.find("literal 42") != std::string::npos); REQUIRE(contents.find("runtime 43") != std::string::npos); REQUIRE(contents.find("no arguments") != std::string::npos); REQUIRE(contents.find("[invalid log format]") != std::string::npos); } #define TEST_PAIR(p, s, s2) \ REQUIRE(p.first == s); \ Loading Loading
include/client/logging.hpp +3 −3 Changes for include/client/logging.hpp: 3 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -412,7 +412,7 @@ struct logger { template <typename... Args> inline void log(log_level level, const char* const func, const int lineno, Args&&... args) { fmt::string_view format, Args&&... args) { if(!(level & log_mask_)) { return; Loading @@ -437,8 +437,8 @@ struct logger { } try { fmt::format_to(std::back_inserter(buffer), std::forward<Args>(args)...); fmt::vformat_to(std::back_inserter(buffer), format, fmt::make_format_args(args...)); } catch(const fmt::format_error&) { // Logging must never terminate the intercepted application. This // fallback is especially important on failed RPC paths, where an Loading
tests/unit/test_path.cpp +27 −0 Changes for tests/unit/test_path.cpp: 27 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -40,6 +40,33 @@ #include <catch2/catch_all.hpp> #include <client/path.hpp> #include <client/preload.hpp> #include <client/logging.hpp> #include "helpers/helpers.hpp" TEST_CASE("client logger accepts runtime formats", "[logging]") { helpers::temporary_directory directory; const auto path = directory.dirname() / "client.log"; { gkfs::log::logger logger("info", path.string(), false, true #ifdef GKFS_DEBUG_BUILD , "", 0 #endif ); const std::string format = "runtime {}"; logger.log(gkfs::log::info, __func__, __LINE__, "literal {}", 42); logger.log(gkfs::log::info, __func__, __LINE__, format, 43); logger.log(gkfs::log::info, __func__, __LINE__, "no arguments"); REQUIRE_NOTHROW(logger.log(gkfs::log::info, __func__, __LINE__, "malformed {")); } std::string contents; helpers::load_string_file(path, contents); REQUIRE(contents.find("literal 42") != std::string::npos); REQUIRE(contents.find("runtime 43") != std::string::npos); REQUIRE(contents.find("no arguments") != std::string::npos); REQUIRE(contents.find("[invalid log format]") != std::string::npos); } #define TEST_PAIR(p, s, s2) \ REQUIRE(p.first == s); \ Loading