From 2d8b992e23ecf7dcd0742420e92fac4a7c290d4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20G=C3=BCndling?= Date: Tue, 21 Jan 2025 12:36:22 +0100 Subject: [PATCH] Accept string view as extra param inline (#36) * log: adding support for passing string_view inline * logging: use perfect forwarding * formatting --------- Co-authored-by: Lucas Cimon <925560+Lucas-C@users.noreply.github.com> --- .pkg | 2 +- include/utl/logging.h | 3 +-- test/logging_test.cc | 9 +++++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.pkg b/.pkg index 3ac0515..2c2de16 100644 --- a/.pkg +++ b/.pkg @@ -9,7 +9,7 @@ [fmt] url=git@github.com:motis-project/fmt.git branch=master - commit=edb385ac526c24bc917ec4a41bb0edb28f0ca59e + commit=dc10f83be70ac2873d5f8d1ce317596f1fd318a2 [cista] url=git@github.com:felixguendling/cista.git branch=master diff --git a/include/utl/logging.h b/include/utl/logging.h index 9daac64..888be98 100644 --- a/include/utl/logging.h +++ b/include/utl/logging.h @@ -48,8 +48,7 @@ inline std::string now() { /// Produce a new log line at the given `level`. template struct log { - log(const char* ctx, fmt::format_string fmt_str, - const Args&&... args, + log(const char* ctx, fmt::format_string fmt_str, Args&&... args, std::source_location const& loc = std::source_location::current()) : loc_{loc}, ctx_{ctx}, diff --git a/test/logging_test.cc b/test/logging_test.cc index 1bc807b..1aee74f 100644 --- a/test/logging_test.cc +++ b/test/logging_test.cc @@ -52,6 +52,15 @@ TEST(log, accept_string_view_as_extra_param) { "Hello world!\n")); }; +TEST(log, accept_string_view_as_extra_param_inline) { + testing::internal::CaptureStderr(); + std::string str{"world"}; + utl::log_info("MyCtx", "Hello {}!", std::string_view{str}); + EXPECT_THAT(testing::internal::GetCapturedStderr(), + MatchesRegex(".+T.+Z \\[info\\] \\[logging.+:.+\\] \\[MyCtx\\] " + "Hello world!\n")); +}; + TEST(log, can_have_optional_attrs) { testing::internal::CaptureStderr(); utl::log_info("MyCtx", "Message").attrs({{"key", "value"}});